Newbie Using "Programming Python" 1st Ed. Question

Gerson Kurz gerson.kurz at t-online.de
Mon Dec 16 12:15:24 EST 2002


On Mon, 16 Dec 2002 10:35:25 -0600, "mowestusa"
<justnotworking at mail.com> wrote:

>Now I know that it must be having trouble with the * but I don't understand
>why.  This is exactly how Mark Lutz tells you to write out the command on
>the command line.  You can use * all the time on the command line and MS-DOS
>knows what you want.

Not quite. Wildcard expansion (which the * is all about) is done by
the shell on unixoid operating systems such as BSD and Linux, but not
by the MS-DOS command line. You have the following options:

a) Try using a port of a unix shell on windows. For example, cygwin
(see http://www.cygwin.com/) is quite usable. If you run that sample
in a cygwin bash shell on windows, it'll work

b) Expand it yourself, e.g. using

import os, fnmatch

def expand_wildcards(pattern):
    # get name of directory without wildcards
    dirname = os.path.dirname(pattern)

    # get name of pattern
    pattern = os.path.basename(pattern)

    # list all files
    return fnmatch.filter( os.listdir(dirname), pattern )

    
    



More information about the Python-list mailing list