I need to know the code to create a notepad file straight from Python.
I have been searching for it but I cant find it. My teacher said that it should create a file automatically. I tried to use:
filename=raw_input("")
target = open (filename, 'a')
It works just fine if I don't put it into a while
loop or an if
statement.
As soon as I do though the whole thing blows.
I am trying to create an option menu to chose between reading or writing.
def main():
foo = open("filename.txt", "w")
foo.write('blah-blah-blah')
foo.close()
main()
if option == '2':
def main2():
foo = open("filename.txt", "r")
print(foo.read())
foo.close()
main2()
keepgoing=input("Enter another statement?(y or n):")
again=input("Run simulation again?(y or n): ")
print()
if again!= "y":
again=False