[英]Unable to read csv file present in Unix in Python
我想读取Unix
中存在的CSV文件,其路径为-/var/ /var/lib/Folder/abc.csv
我正在使用下面的代码读取此文件,但看起来它没有返回任何行,因此它不在for循环内。
file_path = "/var/lib/Folder/abc.csv"
with open(file_path, newline='') as csv_file:
reader = csv.reader(csv_file)
for row in reader:
logging.debug(str(datetime.datetime.now()) + " Checking rows...")
logging.debug(str(datetime.datetime.now()) + " Row(" + str(count) + ") = " + row)
CSV档案看起来像-
"Account ID","Detail","Description","Date created"
"123456","Customer","Savings","2017/10/24"
我正在使用Python 2.7
当我在本地尝试时,此方法有效。 但是我实际上正在使用Jenkins来运行此文件,并且该文件放置在我的Jenkins主服务器中。 我已使用以下方法将文件从代码服务器复制到jenkins-ssh_shell.open(path + fileName,“ rb”)作为remote_file:open(path + fileName,“ wb”)作为local_file:shutil.copyfileobj(remote_file, local_file)之后,我尝试读取文件,但无法正常工作。 即不进入循环。 有什么想法吗?
尝试将此更改的row
更改为str(row)
file_path = "/var/lib/Folder/abc.csv"
with open(file_path, newline='') as csv_file:
reader = csv.reader(csv_file)
for row in reader:
logging.debug(str(datetime.datetime.now()) + " Checking rows...")
logging.debug(str(datetime.datetime.now()) + " Row(" + str(count) + ") = " + str(row))
您可以尝试以下方法:
reader = csv.reader(csv_file, delimiter=',', quotechar='"')
另外,请尝试查看“阅读器”实际包含的内容。 如果未输入for循环,则表示未正确读取内容。 尝试从那里开始调试。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.