# File Display # Week 8 Ch 10, Ex 1 # Written by Greg Lamb # Last modified: 05/11/2015 #Program creates a file to write to. The data file will be a complete list of numbers. #The program then opens the file in read mode and displays it before closing #Open the file for writing myFile = open('numList.dat','w') #Write a file that is a string of numbers myFile.write("This data file contains a list of integers 0-9\nThey follow:\n") myFile.write(" 0 1 2 3 4 5 6 7 8 9") #Close the file myFile.close() #Import csv to make files read/write user friendly import csv #Open the file with open('numList.dat','r') as myCSVFile: #Uses a comma to separate the values in the file dataFromFile = csv.reader(myCSVFile) #Create a for loop that will run once for each row in the list for row in dataFromFile: for value in row: print(value) #Close the file myCSVFile.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