为什么这个简单的Pythion脚本失败了?Python 2.6.6

Ada*_*eda -1 python

这是脚本

#!/usr/bin/python

class LEG(Structure): 
        _fields_ = [("distance_sm", c_float), ("distance_nm", c_float)]
Run Code Online (Sandbox Code Playgroud)

这是我运行时得到的.

Traceback (most recent call last):
  File "./test.py", line 3, in <module>
    class LEG(Structure): 
NameError: name 'Structure' is not defined
Run Code Online (Sandbox Code Playgroud)

是的,蟒蛇新品,谢谢你的帮助

use*_*ica 5

看起来你正在尝试使用模块中的Structure类型ctypes.您需要导入c_float该模块以及您在该模块中使用的任何其他内容:

from ctypes import Structure, c_float
Run Code Online (Sandbox Code Playgroud)