We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have a class called "Square".
When I put the class in the main file, it works.
But when I put the class into another tab called Square, says: "NameError: global name 'Square' is not defined".
If I write "import Square", says: TypeError: 'module' object is not callable.
What's the problem?
Thank you.
Answers
name the tab differently
sketches should not hold the same name as the class
I tried, but got the same error...
Circle is your class? Or is it in a package? Why are you using import if it is in another tab? When Processing executes, it brings all the code from different tabs together. Keep in mind tabs are physically stored as files. You have to make sure the file is a pde file. If it has another extension, like ".java", then it will behave differently.
Kf
import
a whole ".py" tab, we can use:from Name_of_the_Tab import *
"TabImportTest.pyde":
"Square.py":
"Circle" was a typo.
My class is "Square", the tab is "Square".
GoToLoop gave the right answer: "from Square import *"
My mistake was write only "import Square" .
Thank you guys.
Of course you can be more specific and type in:
from Square import Square
. ;)Oh, right, thanks for the clarification.
Another variation w/
import
only and w/ofrom
. :PHowever, we've gotta use
name_of_the_tab.property_name
instead of justproperty_name
: :-<Oh, nice, the more you know...
Thank you.