In Python, the typical way to expand a wildcard is with the glob module.
either: glob.glob to return a list, or glob.iglob to return an iterator (which may be preferable if a large list is expected).
Here's a solution that uses the argparse and glob modules:
One caveat is that I have noticed that python and bash don't sort the expanded lists in the same way, so if for some reason you need deterministic sorting of input, you should sort the resulting list yourself.
import argparse from glob import glob def main(file_names): print file_names if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("file_names", nargs='*') #nargs='*' tells it to combine all positional arguments into a single list args = parser.parse_args() file_names = list() #go through all of the arguments and replace ones with wildcards with the expansion #if a string does not contain a wildcard, glob will return it as is. for arg in args.file_names: file_names += glob(arg) main(file_names)
see also: http://stackoverflow.com/questions/12501761/passing-multple-files-with-asterisk-to-python-shell-in-windows