|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 opalis 于 2018-3-12 17:45 编辑
读取CSV文件的代码如下,在用,没有出现报错:
a = input ("请输入文件名并回车:" )
a_name = "C:\\Users" + a +".csv"
with open( a_name, 'r') as f: #将话单数据导入到array
read =csv.reader(f)
for item in read:
j = item
temp= []
for i in j:
i =i.strip("\t")
i =i.strip("\n")
i =i.strip(" ")
temp.append(i)
array.append(temp)
但因为文件变成海量,因此,我把若干CSV文件改成1-100等数字的文件名
然后我用上述代码读取单个,没问题,因此我就想通过循环把若干个文件进行调用
于是我把他变成函数
def aaa(nums):
a_name = "C:\\Users\\" + nums +".csv"
with open( a_name, 'r') as f: #将话单数据导入到array
read =csv.reader(f)
for item in read:
j = item
temp= []
for i in j:
i =i.strip("\t")
i =i.strip("\n")
i =i.strip(" ")
temp.append(i)
array.append(temp)
之后我用循环调用
xx = input ("请输入一个数字")
xx = int (xx)
for i in range(1,xx):
xxx= i
xxx = str(xxx)
aaa(xxx)
这样调用函数,但是
UnicodeDecodeError: 'gbk' codec can't decode byte,求助
|
|