Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/csharp-4.0/2.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
在上面的行中插入行(Python)_Python_Csv_Row - Fatal编程技术网

在上面的行中插入行(Python)

在上面的行中插入行(Python),python,csv,row,Python,Csv,Row,我关心的是以下几点。。。 使用此代码: with open(pathTEMP, 'r') as f: reader = csv.reader(f) for row in reader: try: if row[0] in listRoom or row[0] in listElem or row[0] in listElem2 or row[0]

我关心的是以下几点。。。 使用此代码:

with open(pathTEMP, 'r') as f:
                reader = csv.reader(f)
                for row in reader:
                    try:
                        if row[0] in listRoom or row[0] in listElem or row[0] in listElem2 or row[0] in listSousElem:
                            print ('---ok----')
                        else:
                            print(row)
                    except:
                        continue
我得到: (这个('----好----')不是真正的值,但它是为了给出一个更好的想法)

我想得到这个:(只要有一个--ok--“你写这行,否则你把它传给上面的那行)

用这样的东西

with open(pathTEMP, 'r') as f:
                reader = csv.reader(f)
                for row in reader:
                    try:
                        if row[0] in listRoom or row[0] in listElem or row[0] in listElem2 or row[0] in listSousElem:
                            writes the line
                        else:
                            puts the line above
                    except:
                        continue

然后将其写入.csv

什么是变量
listRoom
listElem
。。。在你的情况下使用。你能展示你的原始CSV的一些行吗?是的@MauriceMeyer这些是大的列表,看起来像这样:列表室=[“简介”,“条件与实践”,“观察相关”,“结论”,“一般信息”,“账目”,“外围数据循环”,“循环统计”,“资产价值评估法”,“企业所有权费用”,“股票期权交易”,“自动交易”,“描述失业”,“沟通”,“支配证券”,“期货交易”,“识别BNPP REPM”,“股票交易”,“股票交易”,“描述通用”。…请编辑你的问题,这很难阅读和理解。就这样结束了:“只要有”--好--“你写这行,否则你就把它传给上面的那行”
---ok----['Le sol est recouvert de dalles de moquette en bon']['état.']['Au pied des murs périphériques du lot', ' des']['plinthes en bois également en bon état.']
---ok----
---ok----
---ok----['Il est constitué de dalles de faux plafond qui ne']['font pas appel à de remarques particulières.']
with open(pathTEMP, 'r') as f:
                reader = csv.reader(f)
                for row in reader:
                    try:
                        if row[0] in listRoom or row[0] in listElem or row[0] in listElem2 or row[0] in listSousElem:
                            writes the line
                        else:
                            puts the line above
                    except:
                        continue