Hello,
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)
    qr.add_data(soci)
    qr.make()
    im = qr.make_image()
    im.save('E:/Usuarios/Daniel/Documents/APNAE/QR/test.jpeg')

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,

Dani

Recommended Answers

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.
Cheers!

Dani

Be a part of the DaniWeb community

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