AttributeError: partially initialized module 'struct' has no attribute 'pack' (most likely due to a

向右看齐 2023-07-17 11:20 84阅读 0赞

报错:AttributeError: partially initialized module ‘struct’ has no attribute ‘pack’ (most likely due to a circular import)

struct.py

  1. #!/usr/bin/python3
  2. import struct
  3. # native byteorder
  4. buffer = struct.pack("ihb", 1, 2, 3)
  5. print(repr(buffer))
  6. print(struct.unpack("ihb", buffer))
  7. # data from a sequence, network byteorder
  8. data = [1, 2, 3]
  9. buffer = struct.pack("!ihb", *data)
  10. print(repr(buffer))
  11. print(struct.unpack("!ihb", buffer))

原因:文件名和import的包名一致,把文件名改了就好了

发表评论

表情:
评论列表 (有 0 条评论,84人围观)

还没有评论,来说两句吧...

相关阅读