简体   繁体   English

使用 python-barcode 尝试生成条形码并收到错误消息:AttributeError: 'function' object has no attribute 'get'

[英]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.

相关问题 如何使用变量生成带有 python-barcode 的条码 - How can I use a variable to generate barcode with python-barcode 我收到此错误 AttributeError: 'function' object has no attribute 'hlauncher' while试图从另一个文件中获取属性 - I got this error AttributeError: 'function' object has no attribute 'hlauncher' while trying to get a attribute from another file “python-barcode”库中的错误条形码格式 - Wrong barcode format from “python-barcode” library 尝试使用 Jira Python API 获取数据时出现错误 [AttributeError: 'bool' object has no attribute 'error'] - Getting error [ AttributeError: 'bool' object has no attribute 'error' ] when trying to get data using Jira Python API Ananconda, Windows, Python3.8 & python-barcode; 间歇性地得到:[SpyderKernelApp] 警告 | 没有这样的通信: - Ananconda, Windows, Python3.8 & python-barcode; intermittently get: [SpyderKernelApp] WARNING | No such comm: 在设置视图集时,出现错误 AttributeError: 'function' object has no attribute 'get_extra_actions' - In setting viewset, I got an error AttributeError: 'function' object has no attribute 'get_extra_actions' 不理解 Python 中的错误消息:AttributeError: 'dict' object has no attribute 'append' - Not understanding error message in Python: AttributeError: 'dict' object has no attribute 'append' 尝试在 Python 中进行 Anova 测试时遇到问题; (AttributeError: 'Summary' object 没有属性 'model' ) 错误 - Trouble Trying to get an Anova Test in Python; (AttributeError: 'Summary' object has no attribute 'model' ) Error AttributeError: 类型对象“Message”没有属性“get” - AttributeError: type object 'Message' has no attribute 'get' 我正在尝试让 elasticsearch 和 flask 工作。 这是错误 AttributeError: 'function' object has no attribute 'elasticsearch' - I am trying to get elasticsearch and flask to work. Here is the error AttributeError: 'function' object has no attribute 'elasticsearch'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM