Text processing and opening .txt files.
DKatz225 last edited by
I have a script that i've been using on my laptop for stripping out the time stamps in chat logs. I'm wondering how I need to tweak it to use it with Pythonista. Here it is now:
with open('log.txt', 'r') as logfile:
list_of_lines = logfile.readlines()
list_without_timestamp = [line[21:] for line in list_of_lines]
Put back together:
log_string = ''.join(list_without_timestamp)
Write to new file:
with open('log_without_timestamp.txt', 'w') as new_logfile:
My question is, where do i need to put my log.txt file to let Pythonista see it? I tried creating an empty file and pasting in my text and renaming it log.txt but that didn't seem to work.
If I can't do that can I use <code>clipboard.get()</code> to import the text via the clipboard?
Any help much appreciated.
omz last edited by
All files you create in Pythonista's UI have an (invisible) .py extension, so the "log.txt" file you created is actually "log.txt.py", which is why your script couldn't read it. At the moment, you could either change the file name to "log.txt.py" in your script (probably the easiest), or write the txt file programmatically somehow (various ways to do that, but you couldn't see the file in Pythonista's library because it only shows .py files).