473,594 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

Jun 5 '06 #1
2 2014
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\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?


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>

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
1993
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 alphabet, then a dash(-), and between 1-4 set of numbers and the extension could be in one of the following(in order of importance) - jpg, bmp, tif. If I know part/full of its filename, find the 1st match(just in case there are similar filename)...
13
2761
by: Ruby Tuesdays | last post by:
in win32 installation... is it compiled with it or this is a missing features? Thanks
2
6697
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 schema defines the following simpleType: <xs:simpleType name="cs"> <xs:restriction base="xs:token"> <xs:pattern value="*"/> </xs:restriction> </xs:simpleType>
0
814
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: #pragma once #include "resource.h" #include <comsvcs.h>
2
6141
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
1913
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
3173
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). The README file in the Tools/freeze directory of the Python-2.4.4 distribution says the following (and many other things): Previous versions of Freeze used a pretty simple-minded algorithm to
4
18725
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.... patterns = for p in patterns: if fnmatch.fnmatch(some_file_name, p): return True
9
18044
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'. thank you
0
7946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8251
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8372
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8003
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5408
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3859
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
3897
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1478
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.