[Tutor] path issues
Magnus Lyckå
magnus@thinkware.se
Thu May 1 07:49:01 2003
At 00:55 2003-05-01 -0400, Kirk Bailey wrote:
>ok, got a code problem.
> os.remove('./lists/' + mylist) # this deletes the subscriber file.
> os.remove('./lists/' + mylist + '.*') # remove all files with this
Read the manual.
remove(path)
Remove the file path. ...
In other words, os.remove(x)
is (on unix) more or less the same as
os.system("rm '%s'" % x)
Note the single quotes.
In unix, when you do "rm something*", the shell will perform
a wildcard expansion before it calls the rm program, so rm
will be fed a list of actual file names.
Since you've already made your code unix-specific by not using
os.path functions to manage paths, your simplest solution will
be to use os.system("rm %s" % x), but a more pythonic way would
be to do:
import glob
for fn in glob.glob(x):
os.remove(fn)
--
Magnus Lycka (It's really Lyckå), magnus@thinkware.se
Thinkware AB, Sweden, www.thinkware.se
I code Python ~ The shortest path from thought to working program