前期添加csv库遇到了问题,错误显示如下:
“module ‘pip’ has no attribute ‘main’”
经过上网查询,原因是更新了pip,根据网上提供的代码修改了packaging_tool.py文件,结果出现了新的错误,显示“name pip is not defined”
借鉴了链接网址修改,之后添加成功。
#!/usr/bin/python
# -*- coding: UTF-8 -*-
# 从CSV文件中导出数据
import csv
import sys
filename = 'service.csv'
data = []
try:
with open(filename) as f:
reader = csv.reader(f)
header = next(reader)
data = [row for row in header]
except csv.Error as e:
print("Error reading csv filr at line %s:%s"%(reader.line_num,e))
sys.exit(-1)
if header:
print(header)
print('========')
for datarow in data:
print(datarow)
书中的header= reader.next()修改为了header= next(reader)
因为在Python3中reader没有.next()属性,修改后执行成功。