why does activestate (win98) python not support globbing

Bob Cannard bob_cannard at mentor.com
Thu Apr 12 14:25:43 EDT 2001


"Palmer, Dan [SKY:1G21:EXCH]" wrote:
> 
> I was working through Programing python by Mark Lutz, and I can get Example
> 4-1 working under unix (from the 2.0 tar.gz), but when I tried to run this
> under windows (win98 or win2000) it generates an error.  The following error
> is generated.
> 
> In unix it expands the *.py to all the associated files.  In windows it does
> not.  Why the difference.
>
> pack1.py *.py > packed.txt

This has nothing to do with ActiveState. In Unix the globbing
is performmed by the command shell; your program and the Python
interpreter are given the already-expanded filenames. The
command line interpreter in Windows doesn't do this; you have to
explicitly use the glob package, or something similar, within
your program to expand the wildcards.

> Traceback <most recent call last):
>     File: "C:\Prog_Python\pack1.py", line 19, in ?
>         input = open(name,'r')
> IOError: {Error 22] Invalid argument:'*.py
> 
> ---- Script
> #! /usr/bin/env python
> # File: pack1.py
> # Example 4-1
> 
> import sys
> marker = '::::::'
> 
> for name in sys.argv[1:]:

from glob import glob
for arg in sys.argv[1:]:
    for name in glob(arg):

This generally works in Unix also, where the glob effectively
becomes a no-op.

>  input = open(name, 'r')
>  print marker + name
>  print input.read(),

Cheers,

       Bob.



More information about the Python-list mailing list