can't pass command-line arguments

BartlebyScrivener rpdooling at gmail.com
Sun Apr 9 22:41:31 EDT 2006


I'm still new at this. I can't get this to work as a script. If I just
manually insert the values for sys.argv[1] and sys.argv[2] it works
fine, but I can't pass the variables from the command line. What am I
doing wrong?  On windows xp, python 2.4.3

Thank you

import os
import fnmatch
import sys

def all_files(root, patterns='*', single_level=False,
yield_folders=False):
    # Expand patterns from semicolon-separated string to list
    patterns = patterns.split(';')
    for path, subdirs, files in os.walk(root):
        if yield_folders:
            files.extend(subdirs)
        files.sort()
        for name in files:
            for pattern in patterns:
                if fnmatch.fnmatch(name, pattern):
                    yield os.path.join(path, name)
                    break
        if single_level:
            break

for path in all_files(sysargv[1], sysargv[2]):
    print path

ps - The original script is from the excellent Python Cookbook, but
obviously I'm breaking it by trying to pass arguments to it :)




More information about the Python-list mailing list