Re: [Tutor] decorators, __call__ (able) objects

2009-07-16 Thread Todd Matsumoto
Thanks guys,

In the example the __call__ method has *args and **kws as arguments. Is that 
required?

Also when, in what situation would you use callable objects?

Cheers,

T
 Original-Nachricht 
 Datum: Wed, 15 Jul 2009 12:02:05 -0700
 Von: wesley chun wes...@gmail.com
 An: vince spicer vinces1...@gmail.com, tmatsum...@gmx.net
 CC: Kent Johnson ken...@tds.net, tutor@python.org
 Betreff: Re: [Tutor] decorators, __call__ (able) objects

   Can some one give, or point to some good examples of how @decorators
   work, and __call__ (able) objects?
 
  simple example of calling a class
 
  class myKlass(object):
 
  def __call__(self, *args, **kws):
   print i was called
 
   test = myKlass()
   test()
  i was called
 
 
 close. the example was right, but the description wasn't accurate...
 you meant, calling an instance. i'm going to plagarize and rip this
 right out of section 14.1.4 from Core Python Programming:
 
 Python provides the __call__() special method for classes, which allows a
 programmer to create objects (instances) that are callable. By default,
 the
 __call__() method is not implemented, meaning that most instances are
 not callable. However, if this method is overridden in a class
 definition,
 instances of such a class are made callable. Calling such instance objects
 is
 equivalent to invoking the __call__() method. Naturally, any arguments
 given in the instance call are passed as arguments to __call__().
 
 as far as decorators go, kent's tutorial is great place to start. here
 are 2 more articles plus PEP 318, where they were defined:
 
 http://www.ibm.com/developerworks/linux/library/l-cpdecor.html
 http://www.artima.com/weblogs/viewpost.jsp?thread=240808
 http://www.python.org/dev/peps/pep-0318
 
 in addition, i devoted section 11.3.6 of Core Python to decorators.
 
 finally, it should be mentioned that starting in 2.6, you can now
 decorate *classes*, as seen here in PEP 3129:
 
 http://www.python.org/dev/peps/pep-3129/
 
 hope this helps!
 -- wesley
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Core Python Programming, Prentice Hall, (c)2007,2001
 Python Fundamentals, Prentice Hall, (c)2009
 http://corepython.com
 
 wesley.j.chun :: wescpy-at-gmail.com
 python training and technical consulting
 cyberweb.consulting : silicon valley, ca
 http://cyberwebconsulting.com

-- 
Jetzt kostenlos herunterladen: Internet Explorer 8 und Mozilla Firefox 3 -
sicherer, schneller und einfacher! http://portal.gmx.net/de/go/atbrowser
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decorators, __call__ (able) objects

2009-07-16 Thread Vince Spicer


no the __call__ function can is like any function

def __call__(self, passedin):

or simply 

def __call__(self)


*args and **kws explained   http://www.saltycrane.com/blog/2008/01/how-to-
use-args-and-kwargs-in-python/

On Thursday 16 July 2009 12:09:52 am Todd Matsumoto wrote:
 Thanks guys,

 In the example the __call__ method has *args and **kws as arguments. Is
 that required?

 Also when, in what situation would you use callable objects?

 Cheers,

 T
  Original-Nachricht 

  Datum: Wed, 15 Jul 2009 12:02:05 -0700
  Von: wesley chun wes...@gmail.com
  An: vince spicer vinces1...@gmail.com, tmatsum...@gmx.net
  CC: Kent Johnson ken...@tds.net, tutor@python.org
  Betreff: Re: [Tutor] decorators, __call__ (able) objects
 
Can some one give, or point to some good examples of how
@decorators work, and __call__ (able) objects?
  
   simple example of calling a class
  
   class myKlass(object):
  
   def __call__(self, *args, **kws):
print i was called
  
test = myKlass()
test()
  
   i was called
 
  close. the example was right, but the description wasn't accurate...
  you meant, calling an instance. i'm going to plagarize and rip this
  right out of section 14.1.4 from Core Python Programming:
 
  Python provides the __call__() special method for classes, which allows
  a programmer to create objects (instances) that are callable. By default,
  the
  __call__() method is not implemented, meaning that most instances are
  not callable. However, if this method is overridden in a class
  definition,
  instances of such a class are made callable. Calling such instance
  objects is
  equivalent to invoking the __call__() method. Naturally, any arguments
  given in the instance call are passed as arguments to __call__().
 
  as far as decorators go, kent's tutorial is great place to start. here
  are 2 more articles plus PEP 318, where they were defined:
 
  http://www.ibm.com/developerworks/linux/library/l-cpdecor.html
  http://www.artima.com/weblogs/viewpost.jsp?thread=240808
  http://www.python.org/dev/peps/pep-0318
 
  in addition, i devoted section 11.3.6 of Core Python to decorators.
 
  finally, it should be mentioned that starting in 2.6, you can now
  decorate *classes*, as seen here in PEP 3129:
 
  http://www.python.org/dev/peps/pep-3129/
 
  hope this helps!
  -- wesley
  - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
  Core Python Programming, Prentice Hall, (c)2007,2001
  Python Fundamentals, Prentice Hall, (c)2009
  http://corepython.com
 
  wesley.j.chun :: wescpy-at-gmail.com
  python training and technical consulting
  cyberweb.consulting : silicon valley, ca
  http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Kent Johnson
On Wed, Jul 15, 2009 at 7:41 AM, Todd Matsumototmatsum...@gmx.net wrote:
 Hi,

 Can some one give, or point to some good examples of how @decorators work, 
 and __call__ (able) objects?

Decorators:
http://personalpages.tds.net/~kent37/kk/1.html

Kent
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread vince spicer
simple example of calling a class


class myKlass(object):



On Wed, Jul 15, 2009 at 6:33 AM, Kent Johnson ken...@tds.net wrote:

 On Wed, Jul 15, 2009 at 7:41 AM, Todd Matsumototmatsum...@gmx.net wrote:
  Hi,
 
  Can some one give, or point to some good examples of how @decorators
 work, and __call__ (able) objects?

 Decorators:
 http://personalpages.tds.net/~kent37/kk/1.htmlhttp://personalpages.tds.net/%7Ekent37/kk/1.html

 Kent
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread vince spicer
simple example of calling a class

class myKlass(object):

def __call__(self, *args, **kws):
 print i was called


 test = myKlass()

 test()

 i was called





 On Wed, Jul 15, 2009 at 6:33 AM, Kent Johnson ken...@tds.net wrote:

 On Wed, Jul 15, 2009 at 7:41 AM, Todd Matsumototmatsum...@gmx.net
 wrote:
  Hi,
 
  Can some one give, or point to some good examples of how @decorators
 work, and __call__ (able) objects?

 Decorators:
 http://personalpages.tds.net/~kent37/kk/1.htmlhttp://personalpages.tds.net/%7Ekent37/kk/1.html

 Kent
 ___
 Tutor maillist  -  Tutor@python.org
 http://mail.python.org/mailman/listinfo/tutor



___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread wesley chun
  Can some one give, or point to some good examples of how @decorators
  work, and __call__ (able) objects?

 simple example of calling a class

 class myKlass(object):

 def __call__(self, *args, **kws):
  print i was called

  test = myKlass()
  test()
 i was called


close. the example was right, but the description wasn't accurate...
you meant, calling an instance. i'm going to plagarize and rip this
right out of section 14.1.4 from Core Python Programming:

Python provides the __call__() special method for classes, which allows a
programmer to create objects (instances) that are callable. By default, the
__call__() method is not implemented, meaning that most instances are
not callable. However, if this method is overridden in a class definition,
instances of such a class are made callable. Calling such instance objects is
equivalent to invoking the __call__() method. Naturally, any arguments
given in the instance call are passed as arguments to __call__().

as far as decorators go, kent's tutorial is great place to start. here
are 2 more articles plus PEP 318, where they were defined:

http://www.ibm.com/developerworks/linux/library/l-cpdecor.html
http://www.artima.com/weblogs/viewpost.jsp?thread=240808
http://www.python.org/dev/peps/pep-0318

in addition, i devoted section 11.3.6 of Core Python to decorators.

finally, it should be mentioned that starting in 2.6, you can now
decorate *classes*, as seen here in PEP 3129:

http://www.python.org/dev/peps/pep-3129/

hope this helps!
-- wesley
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Core Python Programming, Prentice Hall, (c)2007,2001
Python Fundamentals, Prentice Hall, (c)2009
http://corepython.com

wesley.j.chun :: wescpy-at-gmail.com
python training and technical consulting
cyberweb.consulting : silicon valley, ca
http://cyberwebconsulting.com
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread vince spicer
agreed much better description, thanks

On Wed, Jul 15, 2009 at 1:02 PM, wesley chun wes...@gmail.com wrote:

   Can some one give, or point to some good examples of how @decorators
   work, and __call__ (able) objects?
 
  simple example of calling a class
 
  class myKlass(object):
 
  def __call__(self, *args, **kws):
   print i was called
 
   test = myKlass()
   test()
  i was called


 close. the example was right, but the description wasn't accurate...
 you meant, calling an instance. i'm going to plagarize and rip this
 right out of section 14.1.4 from Core Python Programming:

 Python provides the __call__() special method for classes, which allows a
 programmer to create objects (instances) that are callable. By default, the
 __call__() method is not implemented, meaning that most instances are
 not callable. However, if this method is overridden in a class definition,
 instances of such a class are made callable. Calling such instance objects
 is
 equivalent to invoking the __call__() method. Naturally, any arguments
 given in the instance call are passed as arguments to __call__().

 as far as decorators go, kent's tutorial is great place to start. here
 are 2 more articles plus PEP 318, where they were defined:

 http://www.ibm.com/developerworks/linux/library/l-cpdecor.html
 http://www.artima.com/weblogs/viewpost.jsp?thread=240808
 http://www.python.org/dev/peps/pep-0318

 in addition, i devoted section 11.3.6 of Core Python to decorators.

 finally, it should be mentioned that starting in 2.6, you can now
 decorate *classes*, as seen here in PEP 3129:

 http://www.python.org/dev/peps/pep-3129/

 hope this helps!
 -- wesley
 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
 Core Python Programming, Prentice Hall, (c)2007,2001
 Python Fundamentals, Prentice Hall, (c)2009
http://corepython.com

 wesley.j.chun :: wescpy-at-gmail.com
 python training and technical consulting
 cyberweb.consulting : silicon valley, ca
 http://cyberwebconsulting.com

___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] decorators, __call__ (able) objects

2009-07-15 Thread Todd Matsumoto
hi kent,

thanks, i read through the link but still haven't got my head around this 
concept.

will read on.

cheers,

t
 Original-Nachricht 
 Datum: Wed, 15 Jul 2009 08:33:33 -0400
 Von: Kent Johnson ken...@tds.net
 An: Todd Matsumoto tmatsum...@gmx.net
 CC: tutor@python.org
 Betreff: Re: [Tutor] decorators, __call__ (able) objects

 On Wed, Jul 15, 2009 at 7:41 AM, Todd Matsumototmatsum...@gmx.net wrote:
  Hi,
 
  Can some one give, or point to some good examples of how @decorators
 work, and __call__ (able) objects?
 
 Decorators:
 http://personalpages.tds.net/~kent37/kk/1.html
 
 Kent

-- 
GRATIS für alle GMX-Mitglieder: Die maxdome Movie-FLAT!
Jetzt freischalten unter http://portal.gmx.net/de/go/maxdome01
___
Tutor maillist  -  Tutor@python.org
http://mail.python.org/mailman/listinfo/tutor