I have a code which generates QR codes from a csv file:

#Importar base de dades
pathFile = ('E:\Usuarios\Daniel\Documents\APNAE\QR\Llistat_socis_alta.csv')
socisAPNAE = pd.read_csv(pathFile, delimiter = ';', encoding='ISO-8859-1')

#generar codi QR
for i in range(0,len(socisAPNAE.index)):    
    soci = socisAPNAE.iloc[i,1:6]
    nom = socisAPNAE.iloc[i,1]
    nom = nom.encode('latin-1')
    qr = QRCode(version=20, error_correction=ERROR_CORRECT_L)
    im = qr.make_image()

I would like to know how can I force the loop to rename the output file (test.jpeg, it is overwritten everytime the loop starts) with the string contained in the variable "nom". Can you help? Also, if you find a way to make the code nicer I'll be glad that you explain it to me. I'm just a beginer!
Thank you so much,


Recommended Answers

  im.save('E:/Usuarios/Daniel/Documents/APNAE/QR/%s.jpeg' % nom)
Jump to Post

All 3 Replies

Check Python module tempfile.

  im.save('E:/Usuarios/Daniel/Documents/APNAE/QR/%s.jpeg' % nom)

Thanks pyTony, it works like a charm.


Be a part of the DaniWeb community

We're a friendly, industry-focused community of 1.19 million developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.