# Assignment 8 exercise 1 # Write to a file and then read from it. # Cory Parker 5/18/15 #This will open the file for writing. myFile = open("numbers.dat",'w') # Writes to the file with carriage return code via \n myFile.write("1\n") myFile.write("2\n") myFile.write("3\n") myFile.write("4\n") myFile.write("5\n") myFile.write("6\n") myFile.write("7\n") myFile.write("8\n") myFile.write("9\n") myFile.write("10\n") # Closes the file, I'm told this is important. myFile.close() #This opens the file again and reads the files written above myFile = open("numbers.dat",'r') #This line of code should display the contents of the file print(myFile.read()) myFile.close()
Run
Reset
Share
Import
Link
Embed
Language▼
English
中文
Python Fiddle
Python Cloud IDE
Follow @python_fiddle
Browser Version Not Supported
Due to Python Fiddle's reliance on advanced JavaScript techniques, older browsers might have problems running it correctly. Please download the latest version of your favourite browser.
Chrome 10+
Firefox 4+
Safari 5+
IE 10+
Let me try anyway!
url:
Go
Python Snippet
Stackoverflow Question