Python获得命令行参数

RT。代码如下:

#coding=utf-8
import sys,string,getopt;

def posiviveParam(val):

	print val;

def negativeParam(val):

	print string.atoi(val)*(-1);

if __name__=='__main__':

	operations,argv = getopt.getopt(sys.argv[1:],'p:n:x');

	for ope,param in operations:

		if ope=='-p':

			posiviveParam(param);

		elif ope=='-n':

			negativeParam(param);


你可能感兴趣的:(Python获得命令行参数)