30 ms·
Thanks! I figured out the open problem.. which was some sort of unicode issue where I had the file saved in c:\Users\.. and I guess when it hit the \U it genera
by Random_Person 16y ago
Thanks!
I figured out the open problem.. which was some sort of unicode issue where I had the file saved in c:\Users\.. and I guess when it hit the \U it generated an escape. that's a pretty weird function. So, moved the file and renamed and fixed that issue.
So, on my own, I had gotten as far as starting the for loop and I was unaware that 'line' actually gave me a workable string. What I was working on was this:
for line in in_file:
tx = in_file.readlines()
because my output needs to be pieces of the line instead of the whole line at a time-- so something like this:
for line in in_file:
tx = in_file.readlines()
out_file.write("<tr bgcolor="006699">"
out_file.write("<td>" + tx[1,10] + "</td>")
out_file.write("<td>" + tx[12, 23] + "</td>")
and so on.
- zephyrfalcon 16y agoThis 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!