天天看点

python命令行参数引用_如何使用python在命令行中传递多个参数

(我的代码):import csv

import re

import string

import sys

import fileinput

import os

import random

import glob

import getopt

def getSymbols(filename):

f = file(filename)

while True:

line = f.readline()

if len(line) == 0:

break

print line,

f.close()

if len(sys.argv) < 2:

print 'No action specified.'

sys.exit()

elif:

print "No option"

sys.exit()

else:

for filename in sys.argv[1]:

readfile(filename)

with open(filename) as f:

for line in f:

if 'symbols' in line:

print "Total Number of Symbols:\n",line.strip(' has ');

getSymbols(filename)

我有一个要求,但我找不到解决方案:

如何在命令行中传递多个文件路径作为参数?

例如:test.py C:\test1.txt C:\test2.txt

我使用上面提到的代码将文件路径作为参数传递,filename是对传递的参数的引用,它应该打印符号总数。请将与此问题相关的示例代码发送给我。