【问题标题】:NameError : name 'pack' is not definedNameError:名称“包”未定义
【发布时间】:2019-12-04 10:01:16
【问题描述】:

我自己编写了一个简单的代码,但它在任何 python IDE 中都不起作用,例如 pycharm 和 Wing IDE。但它在终端中正常工作。

在IDE中,不断出现错误“NameError: name 'pack' is not defined”

我正在使用 kali linux。

我已经尝试过检查 struct.py 文件

from struct import *

packed_data = pack("iif", 6, 19, 4.73)
print(packed_data)

construct.py 代码

__all__ = [
# Functions
'calcsize', 'pack', 'pack_into', 'unpack', 'unpack_from',
'iter_unpack',

# Classes
'Struct',

# Exceptions
'error'
]

from _struct import *
from _struct import _clearcache
from _struct import __doc__

【问题讨论】:

  • 我编辑了,抱歉我不习惯stackoverflow
  • @Colin 你能验证一下是否可以在 python 内置 ide 上导入结构,因为你的代码可以在我的系统上运行
  • @Colin 也检查 python 版本
  • @Doodle 当我输入导入结构时也会弹出。我在我的代码和模块中没有看到任何问题。我的是 3.7.3
  • 我想我现在为什么,因为文件夹中有一个名为 struct 的模块

标签: python module


【解决方案1】:

我建议不要将文件名保留为 struct.py,因为“struct”是 python 中的模块。通过更改文件名再试一次。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-01-24
    • 1970-01-01
    • 2021-01-02
    • 2021-04-15
    • 2019-01-26
    • 2021-10-05
    • 2017-08-16
    相关资源
    最近更新 更多