[Tutor] Fwd: glob and file names

Peter Otten __peter__ at web.de
Fri Jun 6 09:05:44 CEST 2014


Gabriele Brambilla wrote:

> 2014-06-05 22:10 GMT-04:00 Peter Romfeld <peter.romfeld.hk at gmail.com>:
> 
> On Friday, June 06, 2014 10:04 AM, Gabriele Brambilla wrote:
>>>
>>> fiLUMOname = 'Lsum_' + period + '_' + parts[2] + '_' + parts[3] + '_'
>>> + parts[4] + '_*.dat'
>>>
>>> aaa = glob.glob(fiLUMOname)
>>> print(aaa)
>>> fiLUMO = open(aaa[0], 'r')
>>
>> i would do:
>>
>> aaa = glob.glob('Lsum_%s_%s_%s_%s_*.dat' % (period, parts[2], parts[3],
>> parts[4]))
> 
> thanks, it works.

While Peter's way may be easier to read both approaches should give you the 
same result, assuming 'period' and the items in the 'parts' list are all 
strings. There must be an accidental change elsewhere -- maybe you changed 
the current working directory before invoking the script?



More information about the Tutor mailing list