making a class callable

D

dude

I've been struggling with getting my class to behave the way I want
it.

I have python module called ohYeah.py, defined as follows...
#File Begin
class foo:

def __init__(self, arg1):
print arg1
self.ohYeah = arg1

def whatwhat(self):
return self.ohYeah
#EOF

My goal is to be able to instantiate the class foo from another python
module, like so:

# Example Usage
f = foo("wow")
j = foo("amazing")
f.whatwhat()
wow
j.whatwhat()
amazing
#

However, I always get the "module not callable" error. After entering
a "def __call__" method in class foo, still get the same problem. Can
someone please point me in the right direction for being able to
achieve the Example Usage above? I'm sure there is something trivial
I'm missing, but after digging around online for a day, I couldn't
find the missing piece. Thanks in advance.
 
M

MRAB

I've been struggling with getting my class to behave the way I want
it.

I have python module called ohYeah.py, defined as follows...
#File Begin
class foo:

def __init__(self, arg1):
print arg1
self.ohYeah = arg1

def whatwhat(self):
return self.ohYeah
#EOF

My goal is to be able to instantiate the class foo from another python
module, like so:

# Example Usage
f = foo("wow")
j = foo("amazing")
f.whatwhat()
wow
j.whatwhat()
amazing
#

However, I always get the "module not callable" error. After entering
a "def __call__" method in class foo, still get the same problem. Can
someone please point me in the right direction for being able to
achieve the Example Usage above? I'm sure there is something trivial
I'm missing, but after digging around online for a day, I couldn't
find the missing piece. Thanks in advance.

How are you importing it?

It should be something like:

from ohYeah import foo

BTW, the recommendation is for class names to be CamelCase and modules
names to be lowercase.
 
D

dude

How are you importing it?

It should be something like:

     from ohYeah import foo

BTW, the recommendation is for class names to be CamelCase and modules
names to be lowercase.

That was the problem. I was using:
import ohYeah

Thanks!
 
T

Tom Zych

dude said:
....
That was the problem. I was using:
import ohYeah

To get that error, I think you must have been importing
a module named "foo" as well. Or you would have gotten
a NameError instead.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,981
Messages
2,570,188
Members
46,733
Latest member
LonaMonzon

Latest Threads

Top