can't use "glog" to find the path with square bracket

W

winterTTr

I want to list the file with glob .
The path( which is a directory ) is contain square bracket as "[ab]
xxx"
.. However , i can't find how to do it rightly with glob .

with the coding :

{{{
import glob
glob.glob('[ab]xxx' )
}}}

and with the path "[ab]xxx" really exits.
result : []

Is there a way to do it rightly ?

And i know the fact that [ is a special character for glob().
But how can i escape it when using glob?

PS:
Python : 2.5
Platform : Win XP
 
M

MRAB

winterTTr said:
I want to list the file with glob .
The path( which is a directory ) is contain square bracket as "[ab]
xxx"
. However , i can't find how to do it rightly with glob .

with the coding :

{{{
import glob
glob.glob('[ab]xxx' )
}}}

and with the path "[ab]xxx" really exits.
result : []

Is there a way to do it rightly ?

And i know the fact that [ is a special character for glob().
But how can i escape it when using glob?

PS:
Python : 2.5
Platform : Win XP
There's no escape character as such, but you can put '[', '?' and '*' in
a character set in their own:

glob.glob('[[]ab]xxx')
^^^
'[' within [...]
 
W

winterTTr

yes , i works as your advise. Thanks a lot . :)


winterTTr said:
I want to list the file with glob .
The path( which is a directory ) is contain square bracket as "[ab]
xxx"
.  However , i can't find how to do it rightly with glob .
with the coding :
{{{
import glob
glob.glob('[ab]xxx' )
}}}
and with the path "[ab]xxx" really exits.
result : []
Is there a way to do it rightly ?
And i know the fact that  [ is a special character for glob().
But how can i escape it when using glob?
PS:
 Python : 2.5
 Platform : Win XP

There's no escape character as such, but you can put '[', '?' and '*' in
a character set in their own:

     glob.glob('[[]ab]xxx')
                ^^^
                '[' within [...]
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top