我正在尝试制作.csv拆分器。 我应该使用x号og行,并使用原始csv文件中的行数创建新的csv文件。
import os
import csv
fileDir = ('C:\\somedir\\')
fName = input('Write the file name here, without extention: ')
lineNo = int(input('Number of lines pr csv file: '))
fNameF = (fName + '.csv')
filehandler = (fileDir + fNameF)
def split(filehandler, delimiter=',', row_limit=lineNo,
output_name_template='fName_%s.csv', output_path=fileDir, keep_headers=True):
reader = csv.reader(filehandler, delimiter=delimiter)
current_piece = 1
current_out_path = os.path.join(
output_name_template % current_piece
)
current_out_writer = csv.writer(open(current_out_path, 'w'))
current_limit = row_limit
if keep_headers:
headers = reader.next()
current_out_writer.writerow(headers)
for i, row in enumerate(reader):
if i + 1 > current_limit:
current_piece += 1
current_limit = row_limit * current_piece
current_out_path = os.path.join(
output_name_template % current_piece
)
current_out_writer = csv.writer(open(current_out_path, 'w'))
if keep_headers:
current_out_writer.writerow(headers)
current_out_writer.writerow(row)
它运行脚本,但没有任何反应,有人可以帮我吗?
答案 0 :(得分:0)
我认为您根本没有调用函数GDAL_LIBRARY_PATH = 'C:\\Program Files\\GDAL\\gdal203.dll'
。而且您还已经将函数中的所有值都作为参数传递了。检查是否使用以下代码输出。
split()