i just installed python
i am trying to run this script:
import csv
reader = csv.reader(open("some.csv", "rb"))
for row in reader:
print row
i am running on windows.
- do i have to type each line individually into python shell or can i save this code into a text file and then run it from the shell?
- where does some.csv have to be in order to run it? in the same c:\python26 folder?
- what is this code supposed to do?
You can do both! To run the code from a text file (such as ‘csvread.py’, but the extension doesn’t matter), type:
python csvread.pyat the command prompt. Make sure your PATH is set to include the Python installation directory.“some.csv” needs to be in the current directory.
This code opens a Python file descriptor specifically designed to read CSVs. The reader file descriptor then prints out each row of the CSV in order. Check the documentation out for a more detailed example: http://docs.python.org/library/csv.html