我在 Windows 8 上使用 Spyder for Python 2.7。我试图打开并读取 csv 文件并查看其中存储的所有数据,但这就是我得到的结果:
runfile('C:/Users/John/Documents/Python Scripts/FLInsuraneFile.py', wdir='C:/Users/John/Documents/Python Scripts')
<_io.TextIOWrapper name='FL_insurance_sample.csv' mode='r' encoding='cp1252'>
Run Code Online (Sandbox Code Playgroud)
如何才能正确打开文件呢?
您可以使用内置库
import csv
with open('names.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
print(row['first_name'], row['last_name'])
Run Code Online (Sandbox Code Playgroud)
https://docs.python.org/3.5/library/csv.html