Does anyone know how to rename a file with Python?
What I do is that I finish the read function and then I call the other function to make it known. There is no way to do both at the same time, it tells me that another process is using the file.
This is my code:
import csv
def leer():
m1=open("archivo1.csv","rb")
m1_csv=csv.reader(m1)
var = ""
for i,x in enumerate(m1_csv):
lista0 = x[0:1]
lista1 = x[1:2]
header = str1 = ''.join(lista0)
header1 = header[9:13]
str1 = ''.join(lista1)
str1 = str1[1:]
str2 = str1[0:32]
listas = []
listas.append("The next header ")
listas.append(header1)
listas.append("")
if(header1=="goin"):
listas.remove("")
listas.remove("goin")
listas.append("error")
listas.append(" the hash is outdate: "+str2)
elif(header1=="omin"):
listas.remove("")
listas.remove("omin")
listas.append("error")
listas.append(" the hash is outdate: "+str2)
elif( str2 == "074e3e3e82db7610dbeafd95c22d20a2"):
listas.remove("")
listas.append(" is using for speaking")
listas.append(" example bla bla bla the packet")
listas.append(" Incident: you can get powers")
listo=["OUTGOING HEADERS"]
listos=["INCOMING HEADERS"]
m2_c=csv.writer(open("archivo2.csv","a"),lineterminator='\n')
if(i==0):
m2_c.writerow(listo)
if(i==468):
m2_c.writerow(listos)
m2_c.writerow(listas)
m1.close()
Try to do it with the os
method but it gives me an error:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "prueba1.py", line 64, in <module>
leer()
File "prueba1.py", line 54, in leer
os.remove("archivo1.csv")
WindowsError: [Error 32] Le processus ne peut pas accÚde
ier est utilisÚ par un autre processus: 'archivo1.csv'