attribute error using fnmatch

S

s99999999s2003

hi
i have script like this:

from fnmatch import fnmatch
from glob import glob
.....
....
f = ['file1','file2','file3']
r = "d:\\somepath"
pat = "*.bat"
listof_files = [i for i in f if not fnmatch(os.path.join(r,i),pat) and
os.path.isfile(os.path.join(r,i))]
....
...

I get this error:
File "C:\Python24\Lib\fnmatch.py", line 37, in fnmatch
pat = os.path.normcase(pat)
File "C:\Python24\lib\ntpath.py", line 42, in normcase
return s.replace("/", "\\").lower()
AttributeError: replace

But when i do everything in interactive, there is no problem.. What
could be wrong with the script?
My purpose is to find a list of files that does not match pat...
thanks
 
F

Fredrik Lundh

listof_files = [i for i in f if not fnmatch(os.path.join(r,i),pat) and
os.path.isfile(os.path.join(r,i))]
...
..

I get this error:
File "C:\Python24\Lib\fnmatch.py", line 37, in fnmatch
pat = os.path.normcase(pat)
File "C:\Python24\lib\ntpath.py", line 42, in normcase
return s.replace("/", "\\").lower()
AttributeError: replace

But when i do everything in interactive, there is no problem.. What
could be wrong with the script?

nothing, from what I can tell.

did you verify that the code you posted really have the problem (it does
use the 'os' module which isn't important, and doesn't use 'glob' which
is imported, so chances are that you messed something up on the way to
comp.lang.python).

what do you get if you add

print repr(pat), type(pat)

just before the list comprehension ?

</F>
 
F

Fredrik Lundh

did you verify that the code you posted really has the problem (it does
use the 'os' module which isn't important

message.replace("important", "imported")
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top