Re: question about endswith()

2011-03-04 Thread Mauro Caceres
if you could define extension to be a tuple, you could use it this way, which is a little simpler: extensions = ('hdf5',) #works files = ('MOD03.A2010002.1810.005.2010258062733.hdf','MOD03.A2010002.1950.005.2010258063105.hdf','MOD03.A2010002.1950.005.2010258063105.hdf5') for filename in files:

Re: question about endswith()

2011-03-04 Thread Matt Funk
Hi, thanks guys. This is it. The following code will match both hdf and hdf5 for reasons explained in the email from Ethan. extensions = 'hdf5' #doesn't work files = ('MOD03.A2010002.1810.005.2010258062733.hdf','MOD03.A2010002.1950.005.2010258063105.hdf','MOD03.A2010002.1950.005.2010258063105.hdf

Re: question about endswith()

2011-03-04 Thread HMX962b
On 03/03/11 23:39, Matt Funk wrote: > Hi, > i have a list of files, some of which end with .hdf and one of them end > with hdf5. I want to filter the hdf5 file. Thereforei set extensions: hdf5 > I try to filter as below: > if (any(filename.endswith(x) for x in extensions)): > > The problem is that

Re: question about endswith()

2011-03-04 Thread Jean-Michel Pichavant
Matt Funk wrote: Hi Grant, first of all sorry for the many typos in my previous email. To clarify, I have a python list full of file names called 'files'. Every single filename has extension='.hdf' except for one file which has an '.hdf5' extension. When i do (and yes, this is pasted): f

Re: question about endswith()

2011-03-04 Thread Tom Zych
Ethan Furman wrote: > What is extensions? A string or a tuple? I'm guessing a string, > because then you're looking at: > > --> filename.endswith(x) for x in 'hdf5' > > which is the same as > > --> filename.endswith('h') or filename.endswith('d') or > filename.endswith('f') or filename.end

Re: question about endswith()

2011-03-03 Thread Rafael Durán Castañeda
I think you want do this: >>> files = ['file1.hdf', 'file2.hdf', 'file3.hdf5','file4.hdf'] >>> print(''.join(x for x in files if x.endswith('5'))) file3.hdf5 >>> But if you need to use it later: >>> file_hdf5 = [x for x in files if x.endswith('5')] >>> file_hdf5 ['file3.hdf5'] >>> 2011/3/4 Gra

Re: question about endswith()

2011-03-03 Thread Grant Edwards
On 2011-03-04, Matt Funk wrote: > Hi Grant, > first of all sorry for the many typos in my previous email. > > To clarify, I have a python list full of file names called 'files'. > Every single filename has extension='.hdf' except for one file which has > an '.hdf5' extension. When i do (and yes, t

Re: question about endswith()

2011-03-03 Thread Ethan Furman
Matt Funk wrote: Hi, i have a list of files, some of which end with .hdf and one of them end with hdf5. I want to filter the hdf5 file. Thereforei set extensions: hdf5 I try to filter as below: > -->if (any(filename.endswith(x) for x in extensions)): What is extensions? A string or a tuple?

Re: question about endswith()

2011-03-03 Thread Matt Funk
Hi Grant, first of all sorry for the many typos in my previous email. To clarify, I have a python list full of file names called 'files'. Every single filename has extension='.hdf' except for one file which has an '.hdf5' extension. When i do (and yes, this is pasted): for filename in file

Re: question about endswith()

2011-03-03 Thread Grant Edwards
On 2011-03-03, Matt Funk wrote: > i have a list of files, some of which end with .hdf and one of them end > with hdf5. I want to filter the hdf5 file. Thereforei set extensions: hdf5 > I try to filter as below: > if (any(filename.endswith(x) for x in extensions)): > > The problem is that i let's

question about endswith()

2011-03-03 Thread Matt Funk
Hi, i have a list of files, some of which end with .hdf and one of them end with hdf5. I want to filter the hdf5 file. Thereforei set extensions: hdf5 I try to filter as below: if (any(filename.endswith(x) for x in extensions)): The problem is that i let's all files though rather than just the hdf