use object method without initializing object

colas.francis at gmail.com colas.francis at gmail.com
Tue Apr 15 11:39:37 EDT 2008


On 15 avr, 17:27, Reckoner <recko... at gmail.com> wrote:
> would it be possible to use one of an object's methods without
> initializing the object?
>
> In other words, if I have:
>
> class Test:
>   def __init__(self):
>       print 'init'
>   def foo(self):
>       print 'foo'
>
> and I want to use the foo function without hitting the
> initialize constructor function.
>
> Is this possible?

Yes:

In [214]: class Test:
   .....:     def foo(self):
   .....:         print 'foo'
   .....:

In [215]: t = Test()

In [216]: t.foo()
foo




More information about the Python-list mailing list