Construct raw strings?
Benji York
benji at benjiyork.com
Wed Sep 7 18:29:49 EDT 2005
Thomas W wrote:
> I got a stupid problem; on my WinXP-box I want to scan the filesystem
> and enter a path to scan like this :
>
> path_to_scan = 'd:\test_images'
Note the lack of an "r" prefix and the \t sequence above.
> The problem is that some of the parts being joined contains escape
> characters
> If I take the seperate parts and join them using the interpreter,
> like :
>
>>>> f = r'd:\test_images\something\foo\bar\test.jpg'
>
> it works ok and os.path.exists(f) returns True, but I cannot the that
> r' in front using the os.path.join-method in my code.
It's not join that's getting you, it's the non-raw string representation
in path_to_scan. Use either 'd:\test_images' or 'd:\\test_images' instead.
--
Benji York
More information about the Python-list
mailing list