attribute error using fnmatch

Fredrik Lundh fredrik at
Mon Jun 5 08:57:34 CEST 2006

s99999999s2003 at wrote:

> 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\", line 37, in fnmatch
>     pat = os.path.normcase(pat)
>   File "C:\Python24\lib\", 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 

what do you get if you add

     print repr(pat), type(pat)

just before the list comprehension ?


More information about the Python-list mailing list