473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

attribute error using fnmatch

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

Jun 5 '06 #1
2 2006
s9************@yahoo.com 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\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>

Jun 5 '06 #2
> 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")

Jun 5 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Ruby Tuesday | last post by:
In a directory, how to find an image file with part of its filename is known and the file extension could be one of the following(jpg, tiff, bmp,png). The filename always begin between 1 to 3...
13
by: Ruby Tuesdays | last post by:
in win32 installation... is it compiled with it or this is a missing features? Thanks
2
by: Ian Griffiths | last post by:
I have been given a schema, instances of which I'm required to be able to consume and generate. I'd like to be able to manipulate these instances as DataSets internally in my application. The...
0
by: Doug Bailey | last post by:
I am trying to create a coclass attribute for an outproc COM server (i.e. an EXE). The project was created using the ATL Project wizard using .NET2003. The coclass is defined as follows: ...
2
by: kitty | last post by:
Can anybody help me out with how to use fnmatch.h to help with regular expression use in c++ ? Also does fnmatch.h work only in linux ? Thankyou for all your help
2
by: kepioo | last post by:
Hi, I have some files in a directory : Results Log, 11;21AM, Apr 09 2006.txt Results Log, 11;21AM, Apr 08 2006.txt Results Log, 03;59AM, Apr 07 2006.txt otherfile1.txt otherfile2.txt ....
1
by: jmalone | last post by:
I have a python script that I need to freeze on AIX 5.1 (customer has AIX and does not want to install Python). The python script is pretty simple (the only things it imports are sys and socket)....
4
by: abcd | last post by:
I am using fnmatch.fnmatch to find some files. The only problem I have is that it only takes one pattern...so if I want to search using multiple patterns I have to do something like.... ...
9
by: Sreeraj | last post by:
hi, I am a beginner in Python. I wish to know how can i filter a list of strings using wild characters.ie Lets say i have list countries = . I need only the list of string starting with 'a'. ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.