Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/305.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
读取csv文件并在Python中删除\n_Python_Python 2.7 - Fatal编程技术网

读取csv文件并在Python中删除\n

读取csv文件并在Python中删除\n,python,python-2.7,Python,Python 2.7,我试图读取一个CSV文件并将元素放在一个数组中,但是每行的最后一个元素与下面行的第一个元素连接在一起,中间有一个\n。代码如下: f = open("read_file.csv", "r+") lines = f.read().split(',') f.close() print lines exit() 您可能希望使用标准库中的csv模块 import csv with open('read_file.csv', 'r+') as csvfile: lines = csv.re

我试图读取一个CSV文件并将元素放在一个数组中,但是每行的最后一个元素与下面行的第一个元素连接在一起,中间有一个\n。代码如下:

f = open("read_file.csv", "r+")
lines = f.read().split(',')


f.close()
print lines

exit()

您可能希望使用标准库中的csv模块

import csv
with open('read_file.csv', 'r+') as csvfile:
    lines = csv.reader(csvfile)
    for line in lines:
        # do your stuff here

您可能希望使用标准库中的csv模块

import csv
with open('read_file.csv', 'r+') as csvfile:
    lines = csv.reader(csvfile)
    for line in lines:
        # do your stuff here

您可能希望使用标准库中的csv模块

import csv
with open('read_file.csv', 'r+') as csvfile:
    lines = csv.reader(csvfile)
    for line in lines:
        # do your stuff here

您可能希望使用标准库中的csv模块

import csv
with open('read_file.csv', 'r+') as csvfile:
    lines = csv.reader(csvfile)
    for line in lines:
        # do your stuff here
这个怎么样

f = open("read_file.csv", "r+")
lines = f.readlines()
print sum([x.rstrip('\n').split(',') for x in lines],[])
这个怎么样

f = open("read_file.csv", "r+")
lines = f.readlines()
print sum([x.rstrip('\n').split(',') for x in lines],[])
这个怎么样

f = open("read_file.csv", "r+")
lines = f.readlines()
print sum([x.rstrip('\n').split(',') for x in lines],[])
这个怎么样

f = open("read_file.csv", "r+")
lines = f.readlines()
print sum([x.rstrip('\n').split(',') for x in lines],[])