I'm reading filenames from a ascii file using
with open('FilenamesAsciiFile.txt') as f:
content = f.readlines()
Unfortunately when I try to open the file or check wether it exists I get an error:
filename = content[0]
print filename
print type(filename)
--> myFile.h5
--> <type 'str'>
import os.path
os.path.isfile(filename)
--> False
When I hardcode the string everything is working fine
os.path.isfile('myFile.h5')
--> True
Is string the wrong input type for that function?
You need to trim '\n' from lines:
filename = content[0].strip()
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With