I want to learn Python, but I simply can’t get this to work. its really strange …
I have two small code snippets posted here, when they reside in the same tab it works!. But if I put the class into its own tab I get a NameError(?). How can I get this to work properly?
In the main tab I have;
p1 = MyClass()
print(p1.x)
in the second tab I have;
class MyClass(object):
x = 5
2 Likes
We need from "module_name" import "stuff"
in order to use stuff from other “.py” tab files:
CountdownClass2.pyde
"""
Countdown Class II (v1.2.5)
GoToLoop (2017/Aug/30)
Forum.Processing.org/two/discussion/27733/
countdown-class-library-for-java-js-python#Item_3
Forum.Processing.org/two/discussion/23846/
time-delay-in-python-mode#Item_17
This file has been truncated. show original
countdown.py
"""
Countdown Class II (v1.2.5)
GoToLoop (2017/Aug/30)
https://Forum.Processing.org/two/discussion/27733/
countdown-class-library-for-java-js-python#Item_3
https://Forum.Processing.org/two/discussion/23846/
time-delay-in-python-mode#Item_17
This file has been truncated. show original
3 Likes
I did this;
main tab
from Core import Core
core = Core()
def setup():
size(1024, 1024)
background(255,255,255)
def draw():
core.testStuff()
noLoop()
other tab
class Core():
x_ = 7
def __init__(self):
self.field = [0] * 4096
self.arrayStuff = [ 4, 8, 9 ]
def testStuff( self ):
#println( "TEST! " + str( arrayStuff[0] ) )
println( self.arrayStuff[0] )
println( self.field[10] )
now it works perfectly!
Many thx!
3 Likes