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
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
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
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
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
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
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
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
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
| 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
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
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
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
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
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
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__(
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
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
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
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
> 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
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
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
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
在 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
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
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 class method or static method or instance method?
--
http://mail.python.org/mailman/listinfo/python-list
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
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
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
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
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')
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 =
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
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
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
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
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 =
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
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):
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
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
> 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
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):
&
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
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
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&
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
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
50 matches
Mail list logo