GVKun编程网logo

struct.error:必填参数不是整数(必填参数不能为空什么意思)

36

在本文中,您将会了解到关于struct.error:必填参数不是整数的新资讯,同时我们还将为您解释必填参数不能为空什么意思的相关在本文中,我们将带你探索struct.error:必填参数不是整数的奥秘

在本文中,您将会了解到关于struct.error:必填参数不是整数的新资讯,同时我们还将为您解释必填参数不能为空什么意思的相关在本文中,我们将带你探索struct.error:必填参数不是整数的奥秘,分析必填参数不能为空什么意思的特点,并给出一些关于builtins.TypeError:必须为str,而不是字节、builtins.TypeError:必须是 str,而不是 bytes、C ++中''struct''和''typedef struct''之间的区别? - Difference between ''struct'' and ''typedef struct'' in C++?、error: expected constructor, destructor, or typ...的实用技巧。

本文目录一览:

struct.error:必填参数不是整数(必填参数不能为空什么意思)

struct.error:必填参数不是整数(必填参数不能为空什么意思)

我有以下python代码:

velocity = 0rotation = 0vr = velocity + (rotation/2)vl = velocity - (rotation/2)cmd = struct.pack(">Bhh", 145, vr, vl)

我处理以下错误:

File "control.py", line 125, in __init__  cmd = struct.pack(">Bhh", 145, vr, vl)  struct.error: required argument is not an integer

答案1

小编典典

您为传入的参数使用了错误的格式:hformat表示要存储的short,而传入的值(即vrvl)看起来像doubles。

考虑将它们进行类型转换int或使用">Bdd"格式。

builtins.TypeError:必须为str,而不是字节

builtins.TypeError:必须为str,而不是字节

我已经将脚本从Python 2.7转换为3.2,并且有一个错误。

# -*- coding: utf-8 -*-
import time
from datetime import date
from lxml import etree
from collections import OrderedDict

# Create the root element
page = etree.Element('results')

# Make a new document tree
doc = etree.ElementTree(page)

# Add the subelements
pageElement = etree.SubElement(page,'Country',Tim = 'Now',name='Germany',AnotherParameter = 'Bye',Code='DE',Storage='Basic')
pageElement = etree.SubElement(page,'City',Code='PZ',Storage='Basic',AnotherParameter = 'Hello')
# For multiple multiple attributes,use as shown above

# Save to XML file
outFile = open('output.xml','w')
doc.write(outFile)

在最后一行,我得到了这个错误:

builtins.TypeError: must be str,not bytes
File "C:\PythonExamples\XmlReportGeneratorExample.py",line 29,in <module>
  doc.write(outFile)
File "c:\Python32\Lib\site-packages\lxml\etree.pyd",line 1853,in lxml.etree._ElementTree.write (src/lxml/lxml.etree.c:44355)
File "c:\Python32\Lib\site-packages\lxml\etree.pyd",line 478,in lxml.etree._tofilelike (src/lxml/lxml.etree.c:90649)
File "c:\Python32\Lib\site-packages\lxml\etree.pyd",line 282,in lxml.etree._ExceptionContext._raise_if_stored (src/lxml/lxml.etree.c:7972)
File "c:\Python32\Lib\site-packages\lxml\etree.pyd",line 378,in lxml.etree._FilelikeWriter.write (src/lxml/lxml.etree.c:89527)

我已经安装了Python 3.2,并且已经安装了lxml-2.3.win32-py3.2.exe。

在Python 2.7上可以使用。

builtins.TypeError:必须是 str,而不是 bytes

builtins.TypeError:必须是 str,而不是 bytes

我已将我的脚本从 Python 2.7 转换为 3.2,但我有一个错误。

# -*- coding: utf-8 -*-
import time
from datetime import date
from lxml import etree
from collections import OrderedDict

# Create the root element
page = etree.Element('results')

# Make a new document tree
doc = etree.ElementTree(page)

# Add the subelements
pageElement = etree.SubElement(page,'Country',Tim = 'Now',name='Germany',AnotherParameter = 'Bye',Code='DE',Storage='Basic')
pageElement = etree.SubElement(page,'City',Code='PZ',Storage='Basic',AnotherParameter = 'Hello')
# For multiple multiple attributes,use as shown above

# Save to XML file
outFile = open('output.xml','w')
doc.write(outFile)

在最后一行,我得到了这个错误:

builtins.TypeError: must be str,not bytes
File "C:\PythonExamples\XmlReportGeneratorExample.py",line 29,in <module>
  doc.write(outFile)
File "c:\Python32\Lib\site-packages\lxml\etree.pyd",line 1853,in lxml.etree._ElementTree.write (src/lxml/lxml.etree.c:44355)
File "c:\Python32\Lib\site-packages\lxml\etree.pyd",line 478,in lxml.etree._tofilelike (src/lxml/lxml.etree.c:90649)
File "c:\Python32\Lib\site-packages\lxml\etree.pyd",line 282,in lxml.etree._ExceptionContext._raise_if_stored (src/lxml/lxml.etree.c:7972)
File "c:\Python32\Lib\site-packages\lxml\etree.pyd",line 378,in lxml.etree._FilelikeWriter.write (src/lxml/lxml.etree.c:89527)

我已经安装了 Python 3.2,并且已经安装了 lxml-2.3.win32-py3.2.exe。

在 Python 2.7 上它可以工作。

C ++中''struct''和''typedef struct''之间的区别? - Difference between ''struct'' and ''typedef struct'' in C++?

C ++中''struct''和''typedef struct''之间的区别? - Difference between ''struct'' and ''typedef struct'' in C++?

问题:

In C++, is there any difference between: 在C ++中,之间有什么区别:

struct Foo { ... };

and

typedef struct { ... } Foo;

解决方案:

参考一: https://stackoom.com/question/2ZIG/C-中-struct-和-typedef-struct-之间的区别
参考二: https://oldbug.net/q/2ZIG/Difference-between-struct-and-typedef-struct-in-C

error: expected constructor, destructor, or typ...

error: expected constructor, destructor, or typ...

error: expected constructor, destructor, or type conversion before ''.'' token.  
光从这个错误提示是看不出什么问题的,所以不知道原因会感觉很奇怪,C++ 中,全局域只能声明,初始化变量,不能对变量进行赋值,运算,调用函数等操作,谨记.

今天关于struct.error:必填参数不是整数必填参数不能为空什么意思的讲解已经结束,谢谢您的阅读,如果想了解更多关于builtins.TypeError:必须为str,而不是字节、builtins.TypeError:必须是 str,而不是 bytes、C ++中''struct''和''typedef struct''之间的区别? - Difference between ''struct'' and ''typedef struct'' in C++?、error: expected constructor, destructor, or typ...的相关知识,请在本站搜索。

本文标签: