Welcome!
This is the community forum for my apps Pythonista and Editorial.
For individual support questions, you can also send an email. If you have a very short question or just want to say hello — I'm @olemoritz on Twitter.
Text processing and opening .txt files.
-
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:
<PRE>
Read File:
with open('log.txt', 'r') as logfile:
list_of_lines = logfile.readlines()Remove timestamp:
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:
new_logfile.write(log_string)
</PRE>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.
Thanks!
-
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).