xelapond
March 30th, 2008, 07:56 PM
Hello,
I have never programmed with Object Oriented stuff before, so I am really struggling to get it to work. I understand the concept, that you can have multiple instances of an object, and that these instances can have methods, but I my main problem lies with instances and what to do with them. Consider the following code:
def connect_server(pass some stuff):
Do some stuff
instance1 = module1.class1(some stuff)
This creates an instance of class1, instance1. Now, what do I do with instance1 if I want other functions to be able to access and do it? Do I return it? Like this?
def connect_server(pass some stuff):
Do some stuff
instance1 = module1.class1(some stuff)
return instance1
instance1 = connect_server(pass some stuff)
instance1.method1(pass some stuff)
And make is global? Or do I pass it into each function? Or am I totally missing the point? For a final question, how do I make other modules access that instance?
Thanks,
Alex
I have never programmed with Object Oriented stuff before, so I am really struggling to get it to work. I understand the concept, that you can have multiple instances of an object, and that these instances can have methods, but I my main problem lies with instances and what to do with them. Consider the following code:
def connect_server(pass some stuff):
Do some stuff
instance1 = module1.class1(some stuff)
This creates an instance of class1, instance1. Now, what do I do with instance1 if I want other functions to be able to access and do it? Do I return it? Like this?
def connect_server(pass some stuff):
Do some stuff
instance1 = module1.class1(some stuff)
return instance1
instance1 = connect_server(pass some stuff)
instance1.method1(pass some stuff)
And make is global? Or do I pass it into each function? Or am I totally missing the point? For a final question, how do I make other modules access that instance?
Thanks,
Alex