Ok, let me try and explain this to the best of my ability. Lets say I have a class called Foobar:
class Foobar():
def __init__(self, foo, bar, choo):
self.foo = foo
self.bar = bar
self.choo = choo
def doIt(self):
return self.foo + self.bar
and I want to have a set of 10 possibilities of instances of Foobar that I will use in my application. Now my end user does not know or care about the values of foo, bar and choo, but would would like to pick one of the 10 possibilities, which I will label.
So I would like to store their choice in a db (but I only want to store the label, which represents a particular instance of the Foobar class). So that way i can just grab the instance I need.
So I tried setting up all my instances in a module like so (lets call it "my_instances.py")
import Foobar
label_one = Foobar("eenie", "meenie", "miney")
label_two = Foobar("teeny", "toony", "tiny")
...
label_ten = Foobar("biggie", "boogie", "baggie")
and that way, once I have the string from the db that represents their choice, I can grab that instance like so (I'm ignoring how you would get the string, but showing how I'm obtaining the instance).
import my_instances
my_object = getattr(my_instances, 'label_one')
result = my_object.doIt()
I am getting a TypeError: unbound method doIt() must be called with Foobar instance as first argument.
So it appears I'm getting Foobar, but not a real instance of it. Any help would be greatly appreciated. I believe I've explained my scenario enough that is you see a simpler workaround for what I am trying to do, please suggest it.
from Foobar import Foobar