Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Generate multiple Barcode or QR Codes Python

I have a simple csv file with some data as shown:

enter image description here

I’m trying to get my script to read the csv file and generate the barcodes (same file would be idea, but at least if I can get multiple files I can create another script to combine them).

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Here is my script:

f = open('bc.csv')
csv_f = csv.reader(f)
next(csv_f)
for serial in csv_f:
    data = (''.join(serial))
    print(data)
    Code39 = barcode.get_barcode_class('code39')
    code39 = Code39(data, add_checksum=False)
    code39.save('barcodetest')

It runs, but only generates the last code. I know I’m missing something here that will generate multiple files with multiple names, but I am a bit stuck.

>Solution :

You need to differentiate the filename, for example:

f = open('bc.csv')
csv_f = csv.reader(f)
next(csv_f)
for id, serial in enumerate(csv_f):
    data = (''.join(serial))
    print(data)
    Code39 = barcode.get_barcode_class('code39')
    code39 = Code39(data, add_checksum=False)
    code39.save('barcodetest' + str(id))
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading