Bugs item #1580472, was opened at 2006-10-19 11:44 Message generated for change (Comment added) made by potten You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1580472&group_id=5470
Please note that this message will contain a full copy of the comment thread, including the initial issue submission, for this request, not just the latest update. Category: Python Library Group: Python 2.5 Status: Open Resolution: None Priority: 5 Private: No Submitted By: Koblaid (koblaid) Assigned to: Nobody/Anonymous (nobody) Summary: glob.glob("c:\\[ ]\*) doesn't work Initial Comment: OS: Windows 2000 Service Pack 4 Python 2.5 glob.glob() doesn't work in directories named "[ ]" (with a blank in it). Another example is a directory named "A - [Aa-Am]" Example: ######################### C:\>md [] C:\>md "[ ]" C:\>copy anyfile.txt [] 1 Datei(en) kopiert. C:\>copy anyfile.txt "[ ]" 1 Datei(en) kopiert. C:\>python Python 2.5 (r25:51908, Sep 19 2006, 09:52:17) [MSC v.1310 32 bit (Intel)] on win32 Type "help", "copyright", "credits" or "license" for more information. >>> import glob >>> glob.glob ("c:\\[]\*") ['c:\\[]\\anyfile.txt'] >>> glob.glob ("c:\\[ ]\*") [] ######################### The second glob should have resulted the same as the first glob since I copied the same file to both directories. I may be wrong because I'm new to python. But I've tested it a couple of times, and I think it have to be a bug of python or a bug of windows. Greets, Koblaid ---------------------------------------------------------------------- Comment By: Peter Otten (potten) Date: 2006-10-27 12:32 Message: Logged In: YES user_id=703365 Not a bug. "[abc]" matches exactly one character which may be "a", "b" or "c". Therefore "[ ]" matches one space character. If you want a literal "[", put it in brackets, e. g. glob.glob("C:\\[[] ]\\*"). --- By the way, do you think this problem is common enough to warrant the addition of a fnmatch.escape() function? I have something like this in mind: >>> import re >>> r = re.compile("(%s)" % "|".join(re.escape(c) for c in "*?[")) >>> def escape(s): ... return r.sub(r"[\1]", s) ... >>> escape("c:\\[a-z]\\*") 'c:\\[[]a-z]\\[*]' ---------------------------------------------------------------------- Comment By: Josiah Carlson (josiahcarlson) Date: 2006-10-27 06:14 Message: Logged In: YES user_id=341410 This is a known issue with the fnmatch module (what glob uses under the covers). According to the documentation of the translate method that converts patterns into regular expressions... "There is no way to quote meta-characters." The fact that "[]" works but "[ ]" doesn't work is a convenient bug, for those who want to use "[]". If you can come up with some similar but non-ambiguous syntax to update the fnmatch module, I'm sure it would be considered, but as-is, I can't see this as a "bug" per-se. ---------------------------------------------------------------------- You can respond by visiting: https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1580472&group_id=5470 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com