I have trouble with to get a simple class to work

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: :snake:

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!

2 Likes