question about endswith()

HMX962b djc at bembo.invalid
Fri Mar 4 09:52:04 EST 2011


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 i let's all files though rather than just the hdf5
> file. Is there anything i am doing wrong?


try

if filename.endswith('.hdf5'):


your code is testing filename for every (x) extension in a list of
extensions. and any() will return True if one matches the filename

-- 
djc



More information about the Python-list mailing list