syllogismos
syllogismos

Reputation: 660

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

or

python *.py

i'm getting an error saying "Cannot open file named *.py"

but i'm able to open all the python files in vim using this command

vim *.py

python 2.7 in windows 7 command prompt

Upvotes: 0

Views: 1882

Answers (2)

Jon Clements
Jon Clements

Reputation: 142146

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.

(Note - haven't done Windows command lines in a while, so this is 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. 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

Upvotes: 2

Michał Niklas
Michał Niklas

Reputation: 54302

You cannot using standard Windows cmd shell. You can use something like bash from Cygwin, maybe PowerShell.

If you want to open *.py from application like vim but in Python, then you can use glob module.

Upvotes: 1

Related Questions