我在pycharm中创建了一个fileSearch程序,我想用用户的参数在命令行中运行它。在
import os
from os.path import join
lookfor = "*insert file name*"
for root, dirs, files in os.walk("*choose directory*"):
print("searching"), root
if lookfor in files:
print "Found %s" % join(root, lookfor)
break
我想在命令行中使用以下用户输入运行此命令:
^{pr2}$
我不确定您是否可以,但您可以编写第一个代码,询问目录,然后从该代码启动其他代码
您可以将
argparse
用于命令输入参数解析器with option。您也可以使用sys.arv
。有关详细信息,请参阅here。在命令行示例:
python fileSearch.py -fileName filename.txt -Directory C:/MyProgram
对于命令行应用程序,我喜欢使用
Click
包http://click.pocoo.org/5/对你来说应该是这样的。在
然后从命令行运行
^{pr2}$Click拥有大量强大的特性来构建健壮的CLI应用程序。就像我说的,这是我的目标。在
相关问题 更多 >
编程相关推荐