美文网首页
python读取文件夹下的.csv文件

python读取文件夹下的.csv文件

作者: demoxjl | 来源:发表于2020-05-13 14:59 被阅读0次
    import os
    import csv
    def readFile(pathFile):
          fileList = os.listdir(pathFile)
          for file in fileList:
                #路径转换为正常路径
                domain = os.path.abspath(pathFile)
                 path = os.path.join(domain, file)
                  with open(path, 'r', encoding='utf-8') as f:
                            readData = csv.reader(f)
                            result = list(readData)
                            for row in result:
                                 print(row)
    
    if __name__ == '__main__':
            #文件路径单‘\’会报错
            pathFile = 'D:\\user\\ddf\csvfile'
            readFile(pathFile)
    

    相关文章

      网友评论

          本文标题:python读取文件夹下的.csv文件

          本文链接:https://www.haomeiwen.com/subject/npmnnhtx.html