Traceback (most recent call last):
File "C:/ScriptsPython/pythonProject/Criar_Banco.py", line 16, in <module>
with open(nome_arquivo, 'rw') as csvfile, arquivo_temp:
ValueError: must have exactly one of create/read/write/append mode
import csv
import shutil
from tempfile import NamedTemporaryFile
nome_arquivo = 'exemplo.csv'
arquivo_temp = NamedTemporaryFile(delete=False)
with open('exemplo.csv', 'r') as csvfile, arquivo_temp:
reader = csv.DictReader(csvfile)
campos = ['SUBSCRIBERID',
'SERIALNUMBER',
'DEVICE_TYPE_NAME',
'FIRSTCONTACTTIME',
'LASTCONTACTTIME',
'LASTACTIVATIONTIME',
'SOFTWAREVERSION',
'EXTERNALIPADDRESS',
'PRODUCT_CLASS',
'MANUFACTURER',
'OUI',
'MODEL_NAME',
'ACTIVATED',
'DELETED',
'NASIP',
'NASPORT',
'NRC',
'REPLACED_BY',
'SERVICETYPEID',
'UPTIME',
'FIRSTUSAGEDATE',
'HARDWAREVERSION',
'SPECVERSION',
'PROVISIONCODE',
'ADDITIONALHARDWAREVERSION',
'ADDITIONALSOFTWAREVERSION',
'VENDORCONFIGFILENUMBEROFENTRIES',
'MACADDR',
'MAC_5G']
writer = csv.DictWriter(arquivo_temp, fieldnames=campos)
writer.writeheader()
for linha in reader:
print(linha)
if linha['PRODUCT_CLASS'] == 'HGU_Askey_Sophia':
linha['MAC_5G'] = 'teste'
print(linha)
writer.writerow(linha)
shutil.move(arquivo_temp.name, nome_arquivo)