Glob returning an empty list when passed a variable
Steve Holden
steve at holdenweb.com
Fri Feb 9 09:15:51 EST 2007
Neil Webster wrote:
> Hi,
>
> I was wondering whether anybody could help me out.
>
> I have a program, for part of it I am trying to pass a variable to a
> glob function, this returns an empty list. The strange thing is when
> I hard code in the variable the glob section works.
>
> Does anybody have any ideas as why it is not working?
>
> The section of code that is not working is:
>
> # The variable to be passed to the glob function
> area_name_string = '"*% s*"' % (Area_name)
>
> os.chdir(Input)
>
> filename = glob.glob(area_name_string)
>
> Thanks in advance
Because you are trying to match filenames that have a double-quote
character at the start and end? Try
area_name_string = '*% s*' % (Area_name)
Interesting, I never realised until now that you can have spaces between
the percent sign and th format effector.
regards
Steve
--
Steve Holden +44 150 684 7255 +1 800 494 3119
Holden Web LLC/Ltd http://www.holdenweb.com
Skype: holdenweb http://del.icio.us/steve.holden
Blog of Note: http://holdenweb.blogspot.com
See you at PyCon? http://us.pycon.org/TX2007
More information about the Python-list
mailing list