python 不会生成条形码

odopli94  于 2023-01-04  发布在  Python
关注(0)|答案(1)|浏览(245)

我试图用一个相当简单的代码在python中创建一个条形码生成器。我是这个模块的新手,对python有点生疏,所以我想知道是什么导致了代码中的错误

#imports the correct module needed to create the barcodes 
from barcode import EAN13
# imports a module that will create the numbers needed for the barcode
from random import randint

codes = []
barcodes = []
for i in range(100):
    code = randint(1111111111111, 9999999999999)
    while code not in codes:
        codes.append(code)

# creates the barcode object   
for code in codes: 
    barcode = EAN13("{codes}")
    barcodes.append(barcode)

# prints the barcode
print(barcodes(0))


Error caused
will not generate any barcodes because the number cant be saved as a string

i want this to be able to display barcodes
t98cgbkg

t98cgbkg1#

from barcode import EAN13
from random import randint

codes = []
barcodes = []
for i in range(100):
    code = randint(1111111111111, 9999999999999)
    while code not in codes:
        codes.append(code)

# creates the barcode object   
for code in codes:
    code = str(code)
    barcode = EAN13(code)
    barcodes.append(barcode)

# render the first barcode in the list
barcodes[0].render()

相关问题