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.
Writing to file?
-
So I had this working perfectly with just strings and a list. Switched to implementing writing to a file (tiny bit more permanent). All that's missing from this is the implementation of the string and complete implementation of the file writing with property settings AND the global value to pass my "inp()" around.
My question is how to implement file writing and reading. I understand the general idea as I've seen a ton of examples. I however, can not get it to work. I don't even know how to prove the txt exists or not through python. So I'm calling on the amazing pythonista community to help a noob!!
<code>
import console
import osdef inp():
open('list.txt', 'r')
print list(list)
print "-" *11
for line in list:
print line
s = raw_input().title()
if s == "Q":
start()
returndef view():
console.clear()
print("Viewing Data")
inp()
returndef add():
console.clear()
print("Adding Data")
inp()
open('list.txt', 'a').write(s.title())
add()def edit():
console.clear()
print(" Remove?")
inp()
if s in list:
list.remove(s)
edit()
else:
edit()def start():
console.clear()
choice = ["[A]dd to list" , "[V]iew List" , "[E]dit List"]
print("List App")
print('\n'.join(choice))
s = raw_input().title()
if s == "ValueError":
start()
elif s == "A":
add()
elif s == "V":
view()
elif s == "E":
edit()
else:
start()start()
</code>
-
One possible implementation: https://gist.github.com/cclauss/6656495
-
Updated to refactor and add writeListToFile().
-
Wow!! You don't know how much I appreciate that! I'm going to be studying this for a while. THANK YOU THANK YOU!!