can't use "glog" to find the path with square bracket
winterTTr
winterttr at gmail.com
Tue Apr 28 21:20:12 EDT 2009
yes , i works as your advise. Thanks a lot . :-)
On Apr 28, 9:52 am, MRAB <goo... at mrabarnett.plus.com> wrote:
> winterTTr wrote:
> > 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 [...]
More information about the Python-list
mailing list