# Chapter 10 Exercise 1: File Display # This program creates a file called numbers.dat and then displays the numbers in the file # Written by Beth Mela # Last updated May 19th, 2015 # Create/ open the file for write access myFile = open("numbers.dat",'w') # Write to the file myFile.write("1\n") myFile.write("2\n") myFile.write("3\n") myFile.write("4\n") myFile.write("5\n") # Close the file myFile.close() # Open the file myFile= open("numbers.dat",'r') # Read the file print(myFile.read()) # Close the file 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