[英]Using python-barcode trying to generate barcode and got error message: AttributeError: 'function' object has no attribute 'get'
I'm trying to do a simple function that will return.PNG file with barcode and nubmer at it's bottom.我正在尝试做一个简单的 function,它将返回底部带有条形码和数字的 .PNG 文件。 I readed documentation ( https://python-barcode.readthedocs.io/en/stable/barcode.html#creating-barcodes-as-image ) and got no informations how to solve my error.
我阅读了文档 ( https://python-barcode.readthedocs.io/en/stable/barcode.html#creating-barcodes-as-image ) 并没有得到如何解决我的错误的信息。
Here's a code:这是一个代码:
def barcode():
number = '123456789102'
ean = barcode.get('ean13', number, writer = ImageWriter)
PNG = ean.save('ean13')
barcode()
And here's an error这是一个错误
ean = barcode.get("ean13", number, writer = ImageWriter)
AttributeError: 'function' object has no attribute 'get'
What am I doing wrong?我究竟做错了什么? Using same commands like those in documentations work perfectly fine in shell but not as a separate program.
使用与文档中的命令相同的命令在shell中工作得很好,但不能作为单独的程序使用。
You have to rename your function to avoid the error:您必须重命名您的 function 以避免错误:
def _barcode():
number = '123456789102'
ean = barcode.get('ean13', number, writer = ImageWriter)
_barcode()
To save it to PNG, change your code as follows:要将其保存为 PNG,请按如下方式更改代码:
def _barcode():
number = '123456789102'
# ean = barcode.get('ean13', number, writer = ImageWriter)
with open('test.png', 'wb') as f:
_writer = ImageWriter()
EAN13(number, _writer).write(f)
_barcode()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.