cmd.py
# -*- coding: utf-8 -*-
from PySide import QtGui, QtCore
import os,sys
import tory
import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbosity", help="increase output verbosity")
parser.add_argument("-l", "--listdir", help="check root")
args = parser.parse_args()

if args.verbosity:
app = QtGui.QApplication(sys.argv)
trans = tory.Tuopan()
trans.show()
sys.exit(app.exec_())

if args.listdir:
root=os.listdir(args.listdir)
for f in root:
print f


tory.py
#coding=utf-8
import sys
from PySide import QtGui
from PySide import QtCore
class Tuopan(QtGui.QWidget):
def __init__(self):
super(Tuopan, self).__init__()
self.setWindowTitle("Tray!")
self.resize(200,200)
if __name__ == '__main__':
app = QtGui.QApplication(sys.argv)
trans = Tuopan()

trans.show()
sys.exit(app.exec_())

随后在cmd执行命令
python [​​​cmd.py​​​] -v 1 运行一个界面
python [​​​cmd.py​​​] -l d:/ 遍历d:/
即可。

python argparse模块通过后台传递参数_ide

python argparse模块通过后台传递参数_ide_02