[英]how do i pass multiple files as arguments in command line for python using regular expressions?
I'm not able to do this 我做不到
ptags.py *.py ptags.py * .py
or 要么
python *.py python * .py
i'm getting an error saying "Cannot open file named *.py" 我收到一条错误消息:“无法打开名为* .py的文件”
but i'm able to open all the python files in vim using this command 但是我可以使用此命令在vim中打开所有python文件
vim *.py vim * .py
python 2.7 in windows 7 command prompt Windows 7命令提示符中的python 2.7
I'm not sure what the sensible behaviour would be for the interpreter to do when presented with more than one source file - If you just want it to execute all .py
files in the current directory, then you should be explicit. 我不确定当呈现多个源文件时,解释器将采取什么明智的行为-如果只希望它执行当前目录中的所有.py
文件,则应该明确。
(Note - haven't done Windows command lines in a while, so this is OTTOMH): (注意-一段时间没有执行Windows命令行,所以这是OTTOMH):
for %i in (*.py) do python %i
On the other hand - if you're only executing a single source file, and want to expand out matches - then look at glob
or os.listdir
and co. 另一方面-如果您只执行一个源文件,并且想扩展匹配项-那么请查看glob
或os.listdir
和co。 and inside your code loop over that... something like: 并在您的代码循环内...类似:
import sys
from glob import glob
in_pattern = sys.argv[1]
for filenames in glob(in_pattern):
print filename
You cannot using standard Windows cmd
shell. 您不能使用标准Windows cmd
shell。 You can use something like bash from Cygwin, maybe PowerShell. 您可以使用来自Cygwin的bash之类的功能,也可以使用PowerShell。
If you want to open *.py
from application like vim
but in Python, then you can use glob
module. 如果要从vim
应用程序中打开*.py
,但要在Python中打开,则可以使用glob
模块。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.