making a class callable

Santoso Wijaya santoso.wijaya at gmail.com
Thu Mar 3 20:55:48 EST 2011


Are you missing an import?

import ohYeah
f = ohYeah.foo('wow')
...

~/santa


On Thu, Mar 3, 2011 at 5:45 PM, dude <erniedude at gmail.com> wrote:

> 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.
> --
> http://mail.python.org/mailman/listinfo/python-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20110303/fc993a22/attachment-0001.html>


More information about the Python-list mailing list