Re: Superclass static method name from subclass

2022-11-19 Thread Thomas Passin
On 11/13/2022 7:27 AM, Axy via Python-list wrote: On 11/11/2022 16:21, Ian Pilcher wrote: Is it possible to access the name of a superclass static method, when defining a subclass attribute, without specifically naming the super- class? A instance's __bases__ attribute is a sequence

Re: Superclass static method name from subclass

2022-11-13 Thread Axy via Python-list
On 11/11/2022 16:21, Ian Pilcher wrote: Is it possible to access the name of a superclass static method, when defining a subclass attribute, without specifically naming the super- class? Contrived example:   class SuperClass(object):   @staticmethod   def foo():   pass   class

Re: Superclass static method name from subclass

2022-11-11 Thread Thomas Passin
On 11/11/2022 5:07 PM, Ian Pilcher wrote: On 11/11/22 11:02, Thomas Passin wrote: You can define a classmethod in SubClass that seems to do the job: class SuperClass(object):    @staticmethod    def spam():  # "spam" and "eggs" are a Python tradition    print('spam from SuperCla

Re: Superclass static method name from subclass

2022-11-11 Thread Cameron Simpson
On 12Nov2022 09:17, Cameron Simpson wrote: On 11Nov2022 10:21, Ian Pilcher wrote: class SubClass(SuperClass): bar = SuperClass.foo ^^ Is there a way to do this without specifically naming 'SuperClass'? I think not. Then I saw your "Dealing with non-callable classmeth

Re: Superclass static method name from subclass

2022-11-11 Thread Cameron Simpson
On 11Nov2022 10:21, Ian Pilcher wrote: Is it possible to access the name of a superclass static method, when defining a subclass attribute, without specifically naming the super- class? Contrived example: class SuperClass(object): @staticmethod def foo(): pass class

Re: Superclass static method name from subclass

2022-11-11 Thread Ian Pilcher
On 11/11/22 11:02, Thomas Passin wrote: You can define a classmethod in SubClass that seems to do the job: class SuperClass(object):   @staticmethod   def spam():  # "spam" and "eggs" are a Python tradition   print('spam from SuperClass') class SubClass(SuperClass):     @cla

Re: Superclass static method name from subclass

2022-11-11 Thread Ian Pilcher
On 11/11/22 11:29, Dieter Maurer wrote: Ian Pilcher wrote at 2022-11-11 10:21 -0600: class SuperClass(object): @staticmethod def foo(): pass class SubClass(SuperClass): bar = SuperClass.foo ^^ Is there a way to do this without specifi

Re: Superclass static method name from subclass

2022-11-11 Thread Dieter Maurer
Ian Pilcher wrote at 2022-11-11 10:21 -0600: >Is it possible to access the name of a superclass static method, when >defining a subclass attribute, without specifically naming the super- >class? > >Contrived example: > > class SuperClass(object): > @stat

Re: Superclass static method name from subclass

2022-11-11 Thread Thomas Passin
sible to access the name of a superclass static method, when defining a subclass attribute, without specifically naming the super- class? Contrived example:   class SuperClass(object):   @staticmethod   def foo():   pass   class SubClass(SuperClass):   bar = SuperClass.foo

Re: Superclass static method name from subclass

2022-11-11 Thread Lars Liedtke
| VAT ID: DE234663798 Informationen zum Datenschutz | Information about privacy policy https://www.solute.de/ger/datenschutz/grundsaetze-der-datenverarbeitung.php Am 11.11.22 um 17:21 schrieb Ian Pilcher: Is it possible to access the name of a superclass static method, when defining a subclass attribute

Superclass static method name from subclass

2022-11-11 Thread Ian Pilcher
Is it possible to access the name of a superclass static method, when defining a subclass attribute, without specifically naming the super- class? Contrived example: class SuperClass(object): @staticmethod def foo(): pass class SubClass(SuperClass): bar

Re: Why has __new__ been implemented as a static method?

2014-05-04 Thread Ian Kelly
On Sun, May 4, 2014 at 8:16 AM, Steven D'Aprano wrote: > On Sun, 04 May 2014 20:03:35 +1200, Gregory Ewing wrote: > >> Steven D'Aprano wrote: >>> If it were a class method, you would call it by MyBaseClass.__new__() >>> rather than explicitly providing the cls argument. >> >> But that wouldn't be

Re: Why has __new__ been implemented as a static method?

2014-05-04 Thread Rotwang
On 04/05/2014 15:16, Steven D'Aprano wrote: On Sun, 04 May 2014 20:03:35 +1200, Gregory Ewing wrote: Steven D'Aprano wrote: If it were a class method, you would call it by MyBaseClass.__new__() rather than explicitly providing the cls argument. But that wouldn't be any good, because the base

Re: Why has __new__ been implemented as a static method?

2014-05-04 Thread Steven D'Aprano
On Sun, 04 May 2014 20:03:35 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> If it were a class method, you would call it by MyBaseClass.__new__() >> rather than explicitly providing the cls argument. > > But that wouldn't be any good, because the base __new__ needs to receive > the actua

Re: Why has __new__ been implemented as a static method?

2014-05-04 Thread Gregory Ewing
Steven D'Aprano wrote: If it were a class method, you would call it by MyBaseClass.__new__() rather than explicitly providing the cls argument. But that wouldn't be any good, because the base __new__ needs to receive the actual class being instantiated, not the class that the __new__ method bel

Re: Why has __new__ been implemented as a static method?

2014-05-03 Thread Steven D'Aprano
On Sun, 04 May 2014 11:21:53 +1200, Gregory Ewing wrote: > Steven D'Aprano wrote: >> I'm not entirely sure what he means by "upcalls", but I believe it >> means to call the method further up (that is, closer to the base) of >> the inheritance tree. > > I think it means this: > > def __new__(

Re: Why has __new__ been implemented as a static method?

2014-05-03 Thread Gregory Ewing
Steven D'Aprano wrote: I'm not entirely sure what he means by "upcalls", but I believe it means to call the method further up (that is, closer to the base) of the inheritance tree. I think it means this: def __new__(cls): MyBaseClass.__new__(cls) which wouldn't work with a class met

Re: Why has __new__ been implemented as a static method?

2014-05-03 Thread Terry Reedy
I do not care beyond knowing that there is a reason. You might be able to find something by searching the pydev archives at gmane.org for '__new__ static method'. In other words, Guido knows that it 'should' be a class method, if it could be. Normally, I'd chalk

Re: Why has __new__ been implemented as a static method?

2014-05-03 Thread Steven D'Aprano
Factoid: __new__ is a static method, not a class method. I initially thought it would have to be a class method, and that's why I added the classmethod primitive. Unfortunately, with class methods, upcalls don't work right in this case, so I had to make it a static method with an

Why has __new__ been implemented as a static method?

2014-05-03 Thread Jurko Gospodnetić
this some more - I guess having it as a static method allows you to use super() and still create a new 'subclass' when asked to instantiate a base class. Perhaps some sort of a factory pattern implementation like so: class Base: def __new__(cls, x): actual_cla

Re: how to tell a method is classmethod or static method or instance method

2012-02-15 Thread Nathan Rice
> And I'll take this opportunity to plug my dualmethod descriptor: > > http://code.activestate.com/recipes/577030-dualmethod-descriptor/ I use an analogous pattern in SQL Alchemy all the time (it's called hybridmethod/hybridproperty there). +1 to dualmethod, that pattern is great when you want a

Re: how to tell a method is classmethod or static method or instance method

2012-02-14 Thread Zheng Li
gt; | > On 13Feb2012 15:59, Zheng Li wrote: > | > | how to tell a method is class method or static method or instance > method? > | > > | > Maybe a better question is: > | > under what circumstances do you need to figure this out? > | > | I can get "m

Re: how to tell a method is classmethod or static method or instance method

2012-02-14 Thread Cameron Simpson
On 14Feb2012 13:13, Zheng Li wrote: | > On 13Feb2012 15:59, Zheng Li wrote: | > | how to tell a method is class method or static method or instance method? | > | > Maybe a better question is: | > under what circumstances do you need to figure this out? | | I can get "met

Re: how to tell a method is classmethod or static method or instance method

2012-02-13 Thread Zheng Li
eron Simpson wrote: > On 13Feb2012 15:59, Zheng Li wrote: > | how to tell a method is class method or static method or instance method? > > Maybe a better question is: > under what circumstances do you need to figure this out? > > I'm actually quite serious here. Ple

Re: how to tell a method is classmethod or static method or instance method

2012-02-13 Thread 88888 Dihedral
在 2012年2月13日星期一UTC+8下午4时03分24秒,Steven D'Aprano写道: > On Mon, 13 Feb 2012 15:59:27 +0900, Zheng Li wrote: > > > how to tell a method is class method or static method or instance > > method? > > That's a good question, with a subtle answer that depends on exactl

Re: how to tell a method is classmethod or static method or instance method

2012-02-13 Thread Steven D'Aprano
On Mon, 13 Feb 2012 15:59:27 +0900, Zheng Li wrote: > how to tell a method is class method or static method or instance > method? That's a good question, with a subtle answer that depends on exactly what you mean by the question. If you mean the object you get back from ordinar

Re: how to tell a method is classmethod or static method or instance method

2012-02-12 Thread Cameron Simpson
On 13Feb2012 15:59, Zheng Li wrote: | how to tell a method is class method or static method or instance method? Maybe a better question is: under what circumstances do you need to figure this out? I'm actually quite serious here. Please outline what circumstances cause you to want to as

how to tell a method is classmethod or static method or instance method

2012-02-12 Thread Zheng Li
how to tell a method is class method or static method or instance method? -- http://mail.python.org/mailman/listinfo/python-list

Re: help with calling a static method in a private class

2010-09-15 Thread Steven D'Aprano
On Tue, 14 Sep 2010 16:38:50 +0200, Diez B. Roggisch wrote: > And additionally, but simply not using staticmethods at all. It's a > rather obscure feature of python - usually, classmethods are what is > considered a static method in other languages. Are you sure about that? I k

Re: help with calling a static method in a private class

2010-09-15 Thread lallous
nderscore. It is effectless on classes anyway > (they are not hidden because of that). > > And additionally, but simply not using staticmethods at all. It's a > rather obscure feature ofpython- usually, classmethods are what is > considered a static method in other languages. And w

Re: help with calling a static method in a private class

2010-09-14 Thread Bruno Desthuilliers
Diez B. Roggisch a écrit : lallous writes: How can I keep the class private and have the following work: [code] class __internal_class(object): @staticmethod def meth1(s): print "meth1:", s @staticmethod def meth2(s): print "meth2:", __internal_class.m

Re: help with calling a static method in a private class

2010-09-14 Thread Diez B. Roggisch
at all. It's a rather obscure feature of python - usually, classmethods are what is considered a static method in other languages. And with that, even your double underscores work: class __internal_class(object): @classmethod def meth1(cls, s): print "meth1:&q

help with calling a static method in a private class

2010-09-14 Thread lallous
How can I keep the class private and have the following work: [code] class __internal_class(object): @staticmethod def meth1(s): print "meth1:", s @staticmethod def meth2(s): print "meth2:", __internal_class.meth1(s) x = __internal_class() x.meth2('sdf')

Re: Static method

2010-02-18 Thread mk
Bruno Desthuilliers wrote: I think you broke something somewhere. Assuming you're using Python 2.x (>= 2.3 IIRC), my above code works. ARGH! Forgot the "delayed staticmethod" line -- in effect I called staticmethod twice: @staticmethod def print_internal_date(filename): f =

Re: Static method

2010-02-18 Thread Bruno Desthuilliers
mk a écrit : Bruno Desthuilliers wrote: class Foo4(object): """ working solution 2 : use a lambda """ @staticmethod def bar(baaz): print baaz tagada = {'bar': lambda x : Foo4.bar(x)} def test(self, baaz): self.tagada['bar'](baaz) Huh? How does this one

Re: Static method

2010-02-18 Thread mk
Bruno Desthuilliers wrote: class Foo4(object): """ working solution 2 : use a lambda """ @staticmethod def bar(baaz): print baaz tagada = {'bar': lambda x : Foo4.bar(x)} def test(self, baaz): self.tagada['bar'](baaz) Huh? How does this one work? After al

Re: Static method

2010-02-18 Thread Bruno Desthuilliers
mk a écrit : Bruno Desthuilliers wrote: (snip) class Foo2(object): """ naive solution : kinda work, BUT will fail with the real code that has plain functions in 'tagada' """ @staticmethod def bar(baaz): print baaz tagada = {'bar': bar} def test

Re: Static method

2010-02-18 Thread mk
Bruno Desthuilliers wrote: I think I know where the problem is: what resides in tagdata is a static method 'wrapper', not the function itself, according to: Indeed. Sorry, I'm afraid I gave you bad advice wrt/ using a staticmethod here - I should know better :( (well, OTHO sta

Re: Static method

2010-02-18 Thread Bruno Desthuilliers
mk a écrit : I'm trying to get print_internal_date become a static method AND to refer to it in a class attribute 'tagdata' dict. class PYFileInfo(FileInfo): 'python file properties' @staticmethod def print_internal_date(filename): f =

Re: Static method

2010-02-18 Thread Stefan Behnel
mk, 18.02.2010 12:12: > I'm trying to get print_internal_date become a static method AND to > refer to it in a class attribute 'tagdata' dict. > > class PYFileInfo(FileInfo): > 'python file properties' > > @staticmethod > def print_int

Static method

2010-02-18 Thread mk
Hello everyone, Disclaimer: I'm doing this mainly for learning purposes, to feel what it's good for. I'm trying to get print_internal_date become a static method AND to refer to it in a class attribute 'tagdata' dict. class PYFileInfo(FileInfo):

How to identify whether a function is module scoped function or static method of a class by using its fully qualified name

2008-07-02 Thread srinivasan srinivas
Thanks, Srini Best Jokes, Best Friends, Best Food and more. Go to http://in.promos.yahoo.com/groups/bestofyahoo/ -- http://mail.python.org/mailman/listinfo/python-list

Re: defining a method that could be used as instance or static method

2008-03-10 Thread Gerard Flanagan
On Mar 10, 4:39 pm, Sam <[EMAIL PROTECTED]> wrote: > Hello > > I would like to implement some kind of comparator, that could be > called as instance method, or static method. Here is a trivial pseudo > code of what I would like to execute > > >> class MyClass: &g

Re: defining a method that could be used as instance or static method

2008-03-10 Thread Sam
> Did you try that it doesn't work? because it should. Whenever you do > No... -_- I kept on trying things @staticmethod. Thanks for your hint, it works fine! Sam -- http://mail.python.org/mailman/listinfo/python-list

Re: defining a method that could be used as instance or static method

2008-03-10 Thread Diez B. Roggisch
Sam wrote: > Hello > > I would like to implement some kind of comparator, that could be > called as instance method, or static method. Here is a trivial pseudo > code of what I would like to execute > >>> class MyClass: > ...def __init__(self, value): &

defining a method that could be used as instance or static method

2008-03-10 Thread Sam
Hello I would like to implement some kind of comparator, that could be called as instance method, or static method. Here is a trivial pseudo code of what I would like to execute >> class MyClass: ...def __init__(self, value): ...self.value = value ...def comp(self, com

Re: way to define static method

2007-08-22 Thread Bruno Desthuilliers
Eric CHAO a écrit : > Thanks a lot. > > Because I found a solution about static method from > http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52304 This is a largely outdated recipe (while it may be usefull if you have to write code for an old Python version). > And that

Re: way to define static method

2007-08-22 Thread Eric CHAO
Thanks a lot. Because I found a solution about static method from http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52304 And that's a little bit difficult to understand. # direct, naive approach -- doesn't work...: class Class1: def static1(name): print "Hello&

Re: way to define static method

2007-08-22 Thread Marc 'BlackJack' Rintsch
On Wed, 22 Aug 2007 20:34:21 +0100, Eric CHAO wrote: > I think Python uses a very strange way to define static method in a > class. Why not make it like this? What is so strange about it? > class MyClass: > def my_static_method(self): > # self should be None as it&#x

way to define static method

2007-08-22 Thread Eric CHAO
I think Python uses a very strange way to define static method in a class. Why not make it like this? class MyClass: def my_static_method(self): # self should be None as it's a static method # just ignore self I'm a newcomer so maybe it's quite naive. But I jus