If you read paths from a file and pass them to functions like os.path.getsize , you do not need to avoid them. For instance:
>>> with open('name with spaces', 'w') as f: ... f.write('abc\n') >>> os.path.getsize('name with spaces') 4
In fact, in Python there are only a few functions that need spaces because they pass the string to the shell (like os.system ) or because they try to parse your name differently (like subprocess.foo using a string arg instead of arg list).
So let logfile.txt look like this:
/Volumes/My Drive/My Scans/Batch 1/foo bar.tif /Volumes/My Drive/My Scans/Batch 1/spam eggs.tif /Volumes/My Drive/My Scans/Batch 2/another long name.tif
... then something like this will work fine:
with open('logfile.txt') as logf: for line in logf: with open(line.rstrip()) as f: do_something_with_tiff_file(f)
Noticing those * characters in your example, if these are glob patterns, this is good too:
with open('logfile.txt') as logf: for line in logf: for path in glob.glob(line.rstrip()): with open(path) as f: do_something_with_tiff_file(f)
If your problem is completely opposite to what you described, and the file is filled with lines that are escaped and you want to cancel them, decode('string_escape') cancels the erasure in the Python style, and there are different functions for undoing different types of escaping, but without knowing which the kind of escape you want to cancel, it's hard to say which function you want ...
source share