Я ищу программу Python, которая поможет мне удалить внутренние двойные кавычки (с помощью замены функцию) или использовать pop/del для удаления этого столбца из этого файла.
См. мой код ниже, в котором возникают проблемы с удалением столбца
Код: Выделить всё
import os
import csv
import sys
from shutil import copyfile
sourcedir=sys.argv[1]
sourcefile=sys.argv[2]
targetdir=sys.argv[3]
targetfile=sys.argv[4]
qualifierIN=sys.argv[5]
delimiterIN=sys.argv[6]
qualifierOUT=sys.argv[7]
delimiterOUT=sys.argv[8]
curDir = os.getcwd()
sep = os.path.sep
if os.path.exists(sourcedir):
print("Source Directory : {x}".format(x=sourcedir))
os.chdir(sourcedir)
if os.path.isfile(sourcefile):
print("Source File : {x}".format(x=sourcefile))
else:
print("Source File Not Found : ", sourcefile)
else:
print("Source Directory Not Found : ",sourcedir)
sys.exit(5)
if os.path.exists(targetdir):
print ("Target Directory : {x}".format(x=targetdir))
else:
print ("Target Directory Not Found :",targetdir)
os.makedirs(targetdir)
try:
with open(sourcefile, 'rt') as fin:
reader = csv.reader(fin, delimiter=delimiterIN, quotechar=qualifierIN )
os.chdir(targetdir)
with open(targetfile, 'wt') as fout:
writer = csv.writer(fout, quoting=csv.QUOTE_ALL, quotechar=qualifierOUT, delimiter=delimiterOUT)
try:
for row in reader:
index = 0
for field in row:
row[index] = str(row[index].replace(delimiterOUT, "")) # delimiter
row[index] = str(row[index].replace(qualifierOUT, "")) # qualifier
row[index] = str(row[index].replace(';', ""))
row[index] = str(row[index].replace('"', '')) # unix newline
#row[index] = str(row[index].replace('\r\n', "")) # windows newline
index += 1
print(row)
writer.writerow(row)
except csv.Error as e:
print("Error: ", str(e))
sys.exit(25)
finally:
fout.close()
fin.close()
os.chdir(curDir)
except Exception as e:
print("Error : ", str(e))
sys.exit(35)
try:
os.chdir(sourcedir)
os.remove(sourcefile)
copyfile(targetfile, sourcefile)
except Exception as e:
print(str(e))
sys.exit(45)
sys.exit(0)
Заголовок:
Код: Выделить всё
invoice number,invoice date,vendor number,vendor site ID,supplier site CODE,invoice description,invoice currency code,invoice total amount,line number,line amount,line description,account code,business unit,business center,department,issue code,project,task number
Код: Выделить всё
315,1992-02-14,2501,641,PHIL,PRINT INT' T,USD,117,75,71,"PAN - RETRIEVE AND REVIEW REPORT FOR "LIFE LOGO" IN CLASS (2029- 17) RE: REGISTR FEB 8, 2024; REPORT TO CLIENT AND REQUEST INSTRUCTIONS TO PROCEED; UPDATE RECORDS AND ACTION IN DATA.",6400,5951,51820,1172,08,,
Код: Выделить всё
"315","1992-02-14","2501","641","PHIL","PRINT INT' T","USD","117","75","71","PAN - RETRIEVE AND REVIEW REPORT FOR LIFE LOGO IN CLASS (2029- 17) RE: REGISTR FEB 8","2024; REPORT TO CLIENT AND REQUEST INSTRUCTIONS TO PROCEED; UPDATE RECORDS AND ACTION IN DATA.""","6400","5951","51820","1172","08","",""
"
Двойные кавычки текста логотипа Life теперь удалены, но «2024; ОТЧЕТ КЛИЕНТУ И ЗАПРОС ИНСТРУКЦИЙ ДЛЯ ДЕЙСТВИЯ; ОБНОВЛЕНИЕ ЗАПИСЕЙ И ДЕЙСТВИЙ». В ДАННЫХ». перемещается в следующий столбец в таблице базы данных.
Я просто хочу удалить весь этот столбец описания строки из файла.
Итак, я просто хочу удалить всю эту строку столбец описания из файла и просто замените значение null или '' вместо описания строки для всех строк в файле.
Подробнее здесь: https://stackoverflow.com/questions/785 ... -be-passed