【发布时间】:2020-04-29 09:52:26
【问题描述】:
我想从命令行获取多个文件作为输入
#python script.py file1.txt file2.txt file3.txt .... file_N.txt
以下程序只能接受一个文件作为输入
python script.py file1.txt
但我想将多个文件作为输入。
import sys
with open(sys.argv[1], 'r') as file:
wordcount = file.read()
words= wordcount.split()
#print(words)
count = {}
for word in words:
if word in count:
count[word]=count[word] + 1
else:
count[word] = 1
print(count)
【问题讨论】:
-
你能展示你已经尝试过的东西吗?
标签: python python-3.x