Re: method that can be called from a class and also from an instance

2012-11-23 Thread Steven D'Aprano
On Fri, 23 Nov 2012 09:52:25 +0100, Peter Otten wrote: > Steven D'Aprano wrote: >> http://code.activestate.com/recipes/577030/ > > Am I reading that right that you don't invoke method() as > MyClass.method()? No. I give an example and explicitly state: You can use this class without instan

Re: method that can be called from a class and also from an instance

2012-11-23 Thread Peter Otten
Steven D'Aprano wrote: > On Thu, 22 Nov 2012 16:51:27 +0100, Peter Otten wrote: > >> Marc Aymerich wrote: >> >>> Hi, >>> >>> I want to create a method within a class that is able to accept either >>> a class or an instance. > [...] >> Why would you overload a method that way? > > > The use-ca

Re: method that can be called from a class and also from an instance

2012-11-22 Thread Steven D'Aprano
On Thu, 22 Nov 2012 16:51:27 +0100, Peter Otten wrote: > Marc Aymerich wrote: > >> Hi, >> >> I want to create a method within a class that is able to accept either >> a class or an instance. [...] > Why would you overload a method that way? The use-case I have is that I have a number of classe

Re: method that can be called from a class and also from an instance

2012-11-22 Thread Marc Aymerich
On Thursday, November 22, 2012 5:26:59 PM UTC+1, Dave Angel wrote: > On 11/22/2012 11:12 AM, Thomas Bach wrote: > > > On Thu, Nov 22, 2012 at 10:52:56AM -0500, Dave Angel wrote: > > >> On 11/22/2012 10:14 AM, Marc Aymerich wrote: > > >>> I want to create a method within a class that is able to a

Re: method that can be called from a class and also from an instance

2012-11-22 Thread Marc Aymerich
On Thursday, November 22, 2012 4:51:30 PM UTC+1, Peter Otten wrote: > Marc Aymerich wrote: > > > > > Hi, > > > > > > I want to create a method within a class that is able to accept either a > > > class or an instance. > > > > > > class MyClass(object): > > > @magic_decorator > > >

Re: method that can be called from a class and also from an instance

2012-11-22 Thread Dave Angel
On 11/22/2012 11:12 AM, Thomas Bach wrote: > On Thu, Nov 22, 2012 at 10:52:56AM -0500, Dave Angel wrote: >> On 11/22/2012 10:14 AM, Marc Aymerich wrote: >>> I want to create a method within a class that is able to accept either a >>> class or an instance. >>> >> I haven't tried it, but how about i

Re: method that can be called from a class and also from an instance

2012-11-22 Thread Thomas Bach
On Thu, Nov 22, 2012 at 10:52:56AM -0500, Dave Angel wrote: > On 11/22/2012 10:14 AM, Marc Aymerich wrote: > > I want to create a method within a class that is able to accept either a > > class or an instance. > > > > I haven't tried it, but how about if you do a @classmethod decorator, > and the

Re: method that can be called from a class and also from an instance

2012-11-22 Thread Dave Angel
On 11/22/2012 10:14 AM, Marc Aymerich wrote: > Hi, > > I want to create a method within a class that is able to accept either a > class or an instance. > > class MyClass(object): > @magic_decorator > def method(param): > # param can be MyClass (cls) or an instance of MyClass (self)

Re: method that can be called from a class and also from an instance

2012-11-22 Thread Peter Otten
Marc Aymerich wrote: > Hi, > > I want to create a method within a class that is able to accept either a > class or an instance. > > class MyClass(object): > @magic_decorator > def method(param): > # param can be MyClass (cls) or an instance of MyClass (self) > > so I can do some

method that can be called from a class and also from an instance

2012-11-22 Thread Marc Aymerich
Hi, I want to create a method within a class that is able to accept either a class or an instance. class MyClass(object): @magic_decorator def method(param): # param can be MyClass (cls) or an instance of MyClass (self) so I can do something like: instance = MyClass() MyClass.