4 ms·
This is more a question for StackOverflow, but here goes... Since Windows paths use backslashes, you should either escape all of them (not just the \U), or use
by zephyrfalcon 16y ago
This is more a question for StackOverflow, but here goes...
Since Windows paths use backslashes, you should either escape all of them (not just the \U), or use raw strings:
filename = "c:\\Users\\foo.txt"
filename = r"c:\Users\foo.txt"
As it happens, Unix-style forward slashes usually work fine too on Windows:
filename = "c:/Users/foo.txt"
This way, you don't have to rename your files and directories. :-)
Also, if the contents of the line are delimited by spaces, consider the split() method:
"a b c".split()
=> ["a", "b", "c"]
If the format isn't actually as easy as that, take a look at the re and csv modules.
- Random_Person 16y agoToo awesome. As a linux user, I feel ashamed that I never tried to use forward slashes in Windows. I really like that split thing. I'll have to do some more research into it. Figuring out how to do that and assign each split to its own variable and all... Thanks a ton!