从keeprigh导出错误的python代码

2024-04-25 08:58:28 发布

您现在位置:Python中文网/ 问答频道 /正文

我正试图从https://www.keepright.at/interfacing.php#DUMP中筛选出某些错误

我已经设法用我在下面写的代码进行了一些导出,它适用于美国或加拿大,但当我尝试为厄瓜多尔导出时,我没有得到任何结果

我认为问题在于有字符(“,./)在数据的注释部分,我不知道如何避开它们

import csv
import time

print("Welcome to the keepright error filter")
workDir = input("insert the path where keepright_errors.txt can be found:")
print(workDir)
ErrOpt = input("Enter values for the category you want separated by commas ex: 210,300 :  ")
print(ErrOpt)
ErrOpt = ErrOpt.split((","))
print(ErrOpt)
second_col = []
print(
"""
USA  21,22,23,24,25,26,27,28,29,30,31,32,33,34,35,36,37,38,39,40,41,42,43,44,45,49,51,52,53,54,55,56,57,58,59,60,61,62,63,64,65,66,67
CANADA 20,21,22,23
"""
)
AreaOpt = input ("Enter the values for your area of interest separated by coma :    ")
AreaOpt = AreaOpt.split((","))
timestr = time.strftime("%Y%m%d-%H%M%S")  #timestamp for file
with open(str(workDir) + '/keepright_errors.txt', encoding='latin-1', newline='') as csvfile, open(str(workDir) + '/keepright-A' + '-' + timestr + '.csv', 'w', encoding='latin-1') as o:
citire = csv.reader(csvfile, delimiter='\t', quoting=csv.QUOTE_NONE)
next(citire, None)
scriere = csv.writer(o, delimiter='\t', quoting=csv.QUOTE_NONE)
for row in citire:
    row[11] = int(row[11]) / (10 ** 7) #transforming lat/long from integer to float
    row[12] = int(row[12]) / (10 ** 7)
    if row[2] in (ErrOpt):
        if row[0] in (AreaOpt):
            scriere.writerow(row)

Tags: csvthetoinimportforinputtime