无法在 Processing.py 的不同选项卡中访问 class
Can't access a class in different tab in Processing.py
我正在尝试在 Processing.py 中名为 Rockets 的选项卡中创建一个名为 Rocket 的 class。无论我如何导入选项卡(import Rockets
、from Rockets import *
、import Rockets as R
),我都会得到:
AttributeError: 'module' object has no attribute 'Rocket'.
我尝试将 class 定义放在同一个选项卡中,它工作正常,所以我认为这是一个导入问题,但我找不到我的错误。
主选项卡:
import Rockets
w_width = 800
w_height = 900
r1 = Rocket(w_width/2, w_height-30)
def setup ():
size(w_width, w_height)
background(127)
def draw ():
background(127)
r1.show()
Rockets
选项卡
class Rocket(object): #I'm not sure if i must put (object) or not, just saw that in tutorials
def __init__(self, x, y):
self.x = x
self.y = y
self.hgt = 30
self.wdt = 10
def show (self):
rectMode(CENTER)
stroke(255)
strokeWeight(2)
fill(0, 127)
rect(self.x, self.y, self.wdt, self.hgt)
跳过 class 声明中的基础 class (object)
。 Rocket
目前未从任何其他对象继承(请参阅 Inheritance)。
class Rocket(object):
class Rocket:
我们 Rockets
(模块)命名空间:
import Rockets
w_width = 800
w_height = 900
r1 = Rockets.Rocket(w_width/2, w_height-30)
或使用 import-from 语句(参见 Importing * From a Package):
from Rockets import *
w_width = 800
w_height = 900
r1 = Rocket(w_width/2, w_height-30)
我正在尝试在 Processing.py 中名为 Rockets 的选项卡中创建一个名为 Rocket 的 class。无论我如何导入选项卡(import Rockets
、from Rockets import *
、import Rockets as R
),我都会得到:
AttributeError: 'module' object has no attribute 'Rocket'.
我尝试将 class 定义放在同一个选项卡中,它工作正常,所以我认为这是一个导入问题,但我找不到我的错误。
主选项卡:
import Rockets
w_width = 800
w_height = 900
r1 = Rocket(w_width/2, w_height-30)
def setup ():
size(w_width, w_height)
background(127)
def draw ():
background(127)
r1.show()
Rockets
选项卡
class Rocket(object): #I'm not sure if i must put (object) or not, just saw that in tutorials
def __init__(self, x, y):
self.x = x
self.y = y
self.hgt = 30
self.wdt = 10
def show (self):
rectMode(CENTER)
stroke(255)
strokeWeight(2)
fill(0, 127)
rect(self.x, self.y, self.wdt, self.hgt)
跳过 class 声明中的基础 class (object)
。 Rocket
目前未从任何其他对象继承(请参阅 Inheritance)。
class Rocket(object):
class Rocket:
我们 Rockets
(模块)命名空间:
import Rockets
w_width = 800
w_height = 900
r1 = Rockets.Rocket(w_width/2, w_height-30)
或使用 import-from 语句(参见 Importing * From a Package):
from Rockets import *
w_width = 800
w_height = 900
r1 = Rocket(w_width/2, w_height-30)