attribute error using fnmatch

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • s99999999s2003@yahoo.com

    #1

    attribute error using fnmatch

    hi
    i have script like this:

    from fnmatch import fnmatch
    from glob import glob
    .....
    ....
    f = ['file1','file2' ,'file3']
    r = "d:\\somepa th"
    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\Li b\fnmatch.py", line 37, in fnmatch
    pat = os.path.normcas e(pat)
    File "C:\Python24\li b\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

  • Fredrik Lundh

    #2
    Re: attribute error using fnmatch

    s99999999s2003@ yahoo.com wrote:
    [color=blue]
    > 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\Li b\fnmatch.py", line 37, in fnmatch
    > pat = os.path.normcas e(pat)
    > File "C:\Python24\li b\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?[/color]

    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.pytho n).

    what do you get if you add

    print repr(pat), type(pat)

    just before the list comprehension ?

    </F>

    Comment

    • Fredrik Lundh

      #3
      Re: attribute error using fnmatch

      > did you verify that the code you posted really has the problem (it does[color=blue]
      > use the 'os' module which isn't important[/color]

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

      Comment

      Working...