Nicolas Haller wrote at 2022-3-12 12:05 -0500:
>On 2022-03-10 12:31, Dieter Maurer wrote:
>> Nicolas Haller wrote at 2022-3-9 10:53 -0500:
>>> ...
>>> The documentation about "user-defined generic types"[1] says that I can
>>> fix some types on a child class (class MyDict(Mapping[str, T]):) but
>>>
On 2022-03-10 12:31, Dieter Maurer wrote:
Nicolas Haller wrote at 2022-3-9 10:53 -0500:
...
The documentation about "user-defined generic types"[1] says that I can
fix some types on a child class (class MyDict(Mapping[str, T]):) but
doesn't say much about the signature of the methods I need to
i
Nicolas Haller wrote at 2022-3-9 10:53 -0500:
> ...
>The documentation about "user-defined generic types"[1] says that I can
>fix some types on a child class (class MyDict(Mapping[str, T]):) but
>doesn't say much about the signature of the methods I need to
>implement/override on that child class.
Hello,
I am wondering about a situation involving typing, Generic and a child
class.
The documentation about "user-defined generic types"[1] says that I can
fix some types on a child class (class MyDict(Mapping[str, T]):) but
doesn't say much about the signature of the methods I need to
imp
Hi,
I am using pytest to test my flask end points. I have grouped tests related to
all unauthenticated access in a class as you see below:
@pytest.mark.usefixtures("client_class")
class TestUnauthorizedRecipesAcces:
def test_update_a_recipe(self, create_recipe_record):
recipe = creat
Oscar Benjamin schrieb am 18.11.2015 um 13:52:
> On 18 November 2015 at 07:50, Daniel Haude wrote:
>>
>> I'm trying to implement some (but not all) methods of a Python class in C.
>> What I've found on the Net is:
>> - how to implement entire modules in C so that I can import that module and
>>
On 18 November 2015 at 07:50, Daniel Haude wrote:
>
> I'm trying to implement some (but not all) methods of a Python class in C.
> What I've found on the Net is:
> - how to implement entire modules in C so that I can import that module and
>use the C functions (successfully done it, too).
>
On 11/18/2015 2:50 AM, Daniel Haude wrote:
Hello,
I'm trying to implement some (but not all) methods of a Python class in C.
What I've found on the Net is:
- how to implement entire modules in C so that I can import that module and
use the C functions (successfully done it, too).
- how t
ut I can't find any examples of modules which consist of a mixture of C and
Python, nor modules that define classes of which some members are
implemented in C, others in Python. Of course, once I have the "mixture" bit
figured out I could just define wrapper class methods that ca
On 1/8/2014 2:56 PM, axis.of.wea...@gmail.com wrote:
can someone please explain why the following works, in contrast to the second
example?
Because function attributes of classes become instance methods, with
special behavior, when accessed via an instance of the class.
def decorator(func)
On 08/01/2014 19:56, axis.of.wea...@gmail.com wrote:
can someone please explain why the following works, in contrast to the second
example?
def decorator(func):
def on_call(*args):
print args
return func(args)
return on_call
class Foo:
@decorator
def bar(s
can someone please explain why the following works, in contrast to the second
example?
def decorator(func):
def on_call(*args):
print args
return func(args)
return on_call
class Foo:
@decorator
def bar(self, param1):
print 'inside bar'
f=Foo()
f.bar(4)
Terry Reedy wrote:
it is normal to look for special methods on the class (and superclasses)
> of an object rather than starting with the object itself.
I suspect there was a deliberate change to correct an anomaly, though
this might have been done as part of some other change.
It's a necess
On 9/22/2011 6:21 AM, Gavin Panella wrote:
On Python 2.6 and 3.1 the following code works fine:
class Foo(object):
@classmethod
def __enter__(cls):
print("__enter__")
@classmethod
def __exit__(cls, exc_type, exc_value, traceback):
Mel wrote:
> This seems to work:
>
>
>
> class MetaWith (type):
> @classmethod
> def __enter__(cls):
> print("__enter__")
>
> @classmethod
> def __exit__(cls, exc_type, exc_value, traceback):
> print("__exit__")
>
> class With (object):
> __metaclass__ = Met
Gavin Panella wrote:
> Hi,
>
> On Python 2.6 and 3.1 the following code works fine:
>
> class Foo(object):
>
> @classmethod
> def __enter__(cls):
> print("__enter__")
>
> @classmethod
> def __exit__(cls, exc_type, exc_value, traceback):
>
Am 22.09.2011 12:21 schrieb Gavin Panella:
Hi,
On Python 2.6 and 3.1 the following code works fine:
class Foo(object):
@classmethod
def __enter__(cls):
print("__enter__")
@classmethod
def __exit__(cls, exc_type, exc_value, traceback):
Hi,
On Python 2.6 and 3.1 the following code works fine:
class Foo(object):
@classmethod
def __enter__(cls):
print("__enter__")
@classmethod
def __exit__(cls, exc_type, exc_value, traceback):
print("__exit__")
with Foo
"Prasad, Ramit" writes:
> It seems to me that if I add a function to the list of class attributes it
> will automatically wrap with "self" but adding it to the object directly will
> not wrap the function as a method. Can somebody explain why? I would have
> thought that any function added to
On Tue, 6 Sep 2011 11:10 am Chris Torek wrote:
>>> black_knight = K()
>>> black_knight.spam()
>>> black_knight.eggs()
>>>
>>> the first parameters ... are magic, and invisible.
>>>
>>> Thus, Python is using the "explicit is better than implicit" rule
>>> in the definition, but not at t
On Aug 31, 9:35 am, "T. Goodchild" wrote:
> I’m new to Python, and I love it. The philosophy of the language (and
> of the community as a whole) is beautiful to me.
Welcome aboard mate!
> But one of the things that bugs me
Oh here we go! :-)
> is the requirement th
>Chris Torek writes:
>[snip]
>> when you have [an] instance and call [an] instance or class method:
[note: I have changed the names very slightly here, and removed
additional arguments, on purpose]
>> black_knight = K()
>> black_knight.spam()
>> black_knight.eggs()
>>
>> the first pa
Chris Torek writes:
[snip]
> Instead, we have a syntax where you, the programmer, write out the
> name of the local variable that binds to the first parameter. This
> means the first parameter is visible. Except, it is only visible
> at the function definition -- when you have the instance and
On Sep 2, 2:30 pm, Ian Kelly wrote:
> On Fri, Sep 2, 2011 at 11:51 AM, John Roth wrote:
> >> I don't see how you could get rid of the wrappers. Methods would
> >> still need to be bound, somehow, so that code like this will work:
>
> >> methods = {}
> >> for obj in objs:
> >> if obj.is_flagg
On Fri, Sep 2, 2011 at 11:51 AM, John Roth wrote:
>> I don't see how you could get rid of the wrappers. Methods would
>> still need to be bound, somehow, so that code like this will work:
>>
>> methods = {}
>> for obj in objs:
>> if obj.is_flagged:
>> methods[obj.user_id] = obj.do_wor
On Sep 1, 8:26 am, Ian Kelly wrote:
> On Thu, Sep 1, 2011 at 6:45 AM, John Roth wrote:
> > I personally consider this to be a wart. Some time ago I did an
> > implementation analysis. The gist is that, if self and cls were made
> > special variables that returned the current instance and class
>
On Thu, Sep 1, 2011 at 6:45 AM, John Roth wrote:
> I personally consider this to be a wart. Some time ago I did an
> implementation analysis. The gist is that, if self and cls were made
> special variables that returned the current instance and class
> respectively, then the compiler could determi
On Aug 31, 8:35 am, "T. Goodchild" wrote:
> I’m new to Python, and I love it. The philosophy of the language (and
> of the community as a whole) is beautiful to me.
>
> But one of the things that bugs me is the requirement that all class
> methods have 'self'
> On Aug 31, 5:35 pm, "T. Goodchild" wrote:
>> So why is 'self' necessary on class methods?
>>
>> Just curious about the rationale behind this part of the language.
When instance variables are accessed with the 'self.varname' syntax, it is
On Aug 31, 5:35 pm, "T. Goodchild" wrote:
> I’m new to Python, and I love it. The philosophy of the language (and
> of the community as a whole) is beautiful to me.
>
> But one of the things that bugs me is the requirement that all class
> methods have 'self'
In article <4e5ed670$0$29981$c3e8da3$54964...@news.astraweb.com>
Steven D'Aprano wrote:
>Er, yes, just like I suggested in my opening paragraph, and as I answered
>following the bit you marked as snipped :)
Oops, so you did (went back and re-read it). Must have gotten
interrupted and lost track
On Wed, Aug 31, 2011 at 7:47 PM, Chris Angelico wrote:
> On Thu, Sep 1, 2011 at 10:48 AM, Steven D'Aprano
> wrote:
>> Python classes have a lot of dynamism made possible by the fact that methods
>> are just wrappers around functions with an explicitly declared "self". That
>> dynamism is rarely u
On Thu, Sep 1, 2011 at 10:48 AM, Steven D'Aprano
wrote:
> Python classes have a lot of dynamism made possible by the fact that methods
> are just wrappers around functions with an explicitly declared "self". That
> dynamism is rarely used, but not *that* rarely, and is very useful when
> used. Imp
Chris Torek wrote:
>>There are also static methods, which don't receive any special first
>>argument, plus any other sort of method you can invent, by creating
>>descriptors... but that's getting into fairly advanced territory. ...
> [rest snipped]
>
> I am not sure whether T. Goodchild was askin
On 8/31/2011 1:12 PM, Prasad, Ramit wrote:
def double(obj): return 2*obj.value
class C:
def __init__(self, val):
>> self.value = val
c = C(3)
>> C.double = double
>> c.doub = double
>> # not c.double as that would mask access to C.double in c.double()
>> print(double(c),
C.double(c)
On Wed, Aug 31, 2011 at 11:12 AM, Prasad, Ramit
wrote:
> It seems to me that if I add a function to the list of class attributes it
> will automatically wrap with "self" but adding it to the object directly will
> not wrap the function as a method. Can somebody explain why? I would have
> thoug
>In article <0dc26f12-2541-4d41-8678-4fa53f347...@g9g2000yqb.googlegroups.com>
T. Goodchild asked, in part:
>>... One of the things that bugs me is the requirement that all class
>>methods have 'self' as their first parameter.
In article <4e5e5628$0$29977$
On Wed, Aug 31, 2011 at 10:12 AM, Prasad, Ramit
wrote:
>>def double(obj): return 2*obj.value
>>
>>class C:
>> def __init__(self, val):
>> self.value = val
>>
>>c = C(3)
>>C.double = double
>>c.doub = double
>># not c.double as that would mask access to C.double in c.double() below
>>pr
>def double(obj): return 2*obj.value
>
>class C:
> def __init__(self, val):
> self.value = val
>
>c = C(3)
>C.double = double
>c.doub = double
># not c.double as that would mask access to C.double in c.double() below
>print(double(c), C.double(c), c.double(), c.doub(c))
Sorry if I get
On 8/31/2011 10:35 AM, T. Goodchild wrote:
But one of the things that bugs me is the requirement that all class
methods have 'self' as their first parameter. On a gut level, to me
this seems to be at odds with Python’s dedication to simplicity.
Actually, it is a consequence o
On 2011-08-31, Steven D'Aprano wrote:
> Well obviously the C++ people thought so :)
Well _that's_ certainly a ringing endorsement in the context of
designing a language that's easy to understand and use.
;)
--
Grant Edwards grant.b.edwardsYow! Where's SANDY DUNCAN?
John Gordon wrote:
> In <0dc26f12-2541-4d41-8678-4fa53f347...@g9g2000yqb.googlegroups.com> "T.
> Goodchild" writes:
>
>> So why is 'self' necessary on class methods? It seems to me that the
>> most common practice is that class methods *almost
T. Goodchild wrote:
> So why is 'self' necessary on class methods?
I assume you are talking about the declaration in the method signature:
def method(self, args): ...
rather than why methods have to be called using self.method. If not, there's
already a FAQ for that seco
Hello,
2011/8/31 T. Goodchild :
> But one of the things that bugs me is the requirement that all class
> methods have 'self' as their first parameter. On a gut level, to me
> this seems to be at odds with Python’s dedication to simplicity.
I think the answer to this question
On 2011-08-31, T. Goodchild wrote:
> I?m new to Python, and I love it. The philosophy of the
> language (and of the community as a whole) is beautiful to me.
>
> But one of the things that bugs me is the requirement that all
> class methods have 'self' as their first par
On 8/31/2011 7:35 AM T. Goodchild said...
Just curious about the rationale behind this part of the language.
http://docs.python.org/faq/design.html
--
http://mail.python.org/mailman/listinfo/python-list
In <0dc26f12-2541-4d41-8678-4fa53f347...@g9g2000yqb.googlegroups.com> "T.
Goodchild" writes:
> So why is 'self' necessary on class methods? It seems to me that the
> most common practice is that class methods *almost always* operate on
> the instance that cal
I’m new to Python, and I love it. The philosophy of the language (and
of the community as a whole) is beautiful to me.
But one of the things that bugs me is the requirement that all class
methods have 'self' as their first parameter. On a gut level, to me
this seems to be at odds wit
I didn't phrase that very well. I do see the point about this being "an
instance lookup on a class"...
--
http://mail.python.org/mailman/listinfo/python-list
Thanks for finding that reference in the data model docs! I was about to post
a bug report because in PEP 3119 it says otherwise:
> The primary mechanism proposed here is to allow overloading the built-in
> functions isinstance() and issubclass(). The overloading works as follows:
> The call i
On Tue, Apr 19, 2011 at 4:52 PM, andrew cooke wrote:
> Hi,
>
> I've been staring at this problem, in various forms, all day. Am I missing
> something obvious, or is there some strange hardwiring of isinstance? This
> is with Python 3.2.
>
> class A(metaclass=ABCMeta):
> @clas
OK, sorry, I see the mistake. I'm confusing __class__ on the instance and on
te class (the latter being the metaclass). Sorry again, Andrew
--
http://mail.python.org/mailman/listinfo/python-list
Also, there's something strange about the number of arguments (they're not
consistent between the two examples - the "A" to __instancecheck__ should not
be needed). Yet it compiles and runs like that. Very confused :o(
--
http://mail.python.org/mailman/listinfo/python-list
Hi,
I've been staring at this problem, in various forms, all day. Am I missing
something obvious, or is there some strange hardwiring of isinstance? This is
with Python 3.2.
class A(metaclass=ABCMeta):
@classmethod
def __instancecheck__(cls, instance): return F
ed (would like) to define outside of the
> > > > class. I know this can be done by defining the function and then
> > > > setting it equal to some member of an instance of the class. But,
> > > > because of the complexity of what I'm doing (I have to set ma
e function and then
> > > setting it equal to some member of an instance of the class. But,
> > > because of the complexity of what I'm doing (I have to set many
> > > functions as class methods) I would rather not do this. Can someone
> > > show me how to do
g for
here ;)
Also in Python we talk about "attributes", not "members"
> of an instance of the class.
What you describe here will not "define class methods", nor even
instance methods FWIW - it will only make the function an attribute of
the instance, but won&
instance of the class. But,
> > because of the complexity of what I'm doing (I have to set many
> > functions as class methods) I would rather not do this. Can someone
> > show me how to do this? Is it even possible? Can decorators be used
> > here?
>
> Do you m
,
because of the complexity of what I'm doing (I have to set many
functions as class methods) I would rather not do this. Can someone
show me how to do this? Is it even possible? Can decorators be used
here?
Do you mean something like this ?
@classmethod
def foo(cls):
print "I
of what I'm doing (I have to set many
> functions as class methods) I would rather not do this. Can someone
> show me how to do this? Is it even possible? Can decorators be used
> here?
Do you mean something like this ?
@classmethod
def foo(cls):
print "I am the foo clas
I have some methods that I need (would like) to define outside of the
class. I know this can be done by defining the function and then
setting it equal to some member of an instance of the class. But,
because of the complexity of what I'm doing (I have to set many
functions as class metho
, then this __get__ method is called
(with either the instance or None and the class itself as arguments)
Depending, I assume, on whether this is instance call | class method
call, respectively?
s/call/lookup/
If it's looked up on the class, there's no instance to pass to __get__.
o Python 2.
>
>> The
>> answer is : attribute lookup rules and the descriptor protocol.
>>
>> To make a long story short, the descriptor protocol specify that, when,
>> during an attribute lookup, a name resolves to a class attribute AND
>> this attribut
call, respectively?
Hmm why does the __get__ receive class as argument on top of instance |
None? After all, when having an instance, the class can always be found
by instance.__class__ ? Is this for sake of class methods?
Python is science, I gather: an answer to one question bears another 10
Ben Finney a écrit :
Bruno Desthuilliers writes:
perhaps a lighter introductory text could be helpful. So guys, if you
think a revised version of my post would be of interest, I'll take you
on words: provide the hosting, I'll provide the content !-)
Here, let me work my hosting magic: http:/
Bruno Desthuilliers writes:
> perhaps a lighter introductory text could be helpful. So guys, if you
> think a revised version of my post would be of interest, I'll take you
> on words: provide the hosting, I'll provide the content !-)
Here, let me work my hosting magic: http://wiki.python.org/>.
Stephen Hansen wrote:
Or just leave it as a top level function where it was perfectly happy to
live :)
Yes. This is probably the sanest solution anyway, because probably
having many such functions to use, packing them into smth like
package.utils anyway is a good idea. I'm trying mainly to le
Mark Lawrence a écrit :
Ben Finney wrote:
Bruno Desthuilliers writes:
Mmmm... Let's try to explain the whole damn thing. It's really (and
IMHO beautifully) simple once you get it, but I agree it's a bit
peculiar when compared to most mainstream OO languages.
[…]
Bruno, that's the first time
Ben Finney wrote:
Bruno Desthuilliers writes:
Mmmm... Let's try to explain the whole damn thing. It's really (and
IMHO beautifully) simple once you get it, but I agree it's a bit
peculiar when compared to most mainstream OO languages.
[…]
Bruno, that's the first time I've understood the desc
Bruno Desthuilliers writes:
> Mmmm... Let's try to explain the whole damn thing. It's really (and
> IMHO beautifully) simple once you get it, but I agree it's a bit
> peculiar when compared to most mainstream OO languages.
[…]
Bruno, that's the first time I've understood the descriptor protocol,
John Posner a écrit :
> On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote:
>>
> Very nice writeup, Bruno -- thanks!
>
>
>>
>>
>> def __call__(self, *args, **kw):
>> # XXX : all sanity checks removed for readability
>> if self.im_self:
>> args = (self.im_func,
Bruno Desthuilliers writes:
[...]
> class Foo(object):
> def bar(self):
> return "baaz"
>
> print Foo.__dict__.keys()
> print type(Foo.__dict__['bar'])
>
>
> So, why is it that type(Foo.bar) != type(Foo.__dict__['bar']) ? The
> answer is : attribute lookup rules and the descriptor pro
On 2/17/2010 2:44 PM, Bruno Desthuilliers wrote:
Mmmm... Let's try to explain the whole damn thing. It's really (and IMHO
beautifully) simple once you get it, but I agree it's a bit peculiar
when compared to most mainstream OO languages.
Very nice writeup, Bruno -- thanks!
class method(ob
mk a écrit :
> Stephen Hansen wrote:
>
>> You don't have to (and can't) refer to the class within the body.
>> Class statements are sort of... odd. They are code which is directly
>> executed, and the results are then passed into a
>> metaclass/type/whatever and a class object is created. While wi
e it
with @staticmethod though.
class A:
@staticmethod
def getInstance():
return A()
a = A.getInstance()
you have also the class method version:
class B:
@classmethod:
def getInstance(cls): # class methods take a class as first parameter
return cls()
JM
--
http://mail.python.org/mailman/listinfo/python-list
On Wed, Feb 17, 2010 at 10:38 AM, mk wrote:
> Thanks, that worked. But in order to make it work I had to get rid of
> 'self' in print_internal_date signature, bc all other functions in tagdata
> have only a single argument:
>
Right, I should have caught that.
You can make print_internal_date a
Stephen Hansen wrote:
You don't have to (and can't) refer to the class within the body. Class
statements are sort of... odd. They are code which is directly executed,
and the results are then passed into a metaclass/type/whatever and a
class object is created. While within the class body, the
On Wed, Feb 17, 2010 at 9:38 AM, mk wrote:
> It works. But if I'd like to def print_internal_date in PYFileInfo body
> like so:
>
> class PYFileInfo(FileInfo):
>'python file properties'
>
>def print_internal_date(self, filename):
>f = open(filename + 'c', "rb")
>data = f.r
Hello everyone,
OK so I have this:
def print_internal_date(filename):
f = open(filename + 'c', "rb")
data = f.read(8)
mtime = struct.unpack("It works. But if I'd like to def print_internal_date in PYFileInfo body
like so:
class PYFileInfo(FileInfo):
'python file properties'
On Sep 6, 5:49 pm, Terry Reedy wrote:
> lkclwrote:
> > On Aug 21, 12:58 am, a...@pythoncraft.com (Aahz) wrote:
> >> In article
> >> <77715735-2668-43e7-95da-c91d175b3...@z31g2000yqd.googlegroups.com>,
>
> >>lkcl wrote:
>
> >>> if somebody would like to add this to the python bugtracker, as a
> >
In article ,
Terry Reedy wrote:
>lkcl wrote:
>> On Aug 21, 12:58 am, a...@pythoncraft.com (Aahz) wrote:
>>> In article
>>> <77715735-2668-43e7-95da-c91d175b3...@z31g2000yqd.googlegroups.com>,
>>> lkcl wrote:
if somebody would like to add this to the python bugtracker, as a
contr
lkcl wrote:
On Aug 21, 12:58 am, a...@pythoncraft.com (Aahz) wrote:
In article <77715735-2668-43e7-95da-c91d175b3...@z31g2000yqd.googlegroups.com>,
lkcl wrote:
if somebody would like to add this to the python bugtracker, as a
contribution, that would be great. alternatively, you might like
On Aug 21, 12:58 am, a...@pythoncraft.com (Aahz) wrote:
> In article
> <77715735-2668-43e7-95da-c91d175b3...@z31g2000yqd.googlegroups.com>,
>
> lkcl wrote:
>
> >if somebody would like to add this to the python bugtracker, as a
> >contribution, that would be great. alternatively, you might like
In article <77715735-2668-43e7-95da-c91d175b3...@z31g2000yqd.googlegroups.com>,
lkcl wrote:
>
>if somebody would like to add this to the python bugtracker, as a
>contribution, that would be great. alternatively, you might like to
>have a word with the python developers to get them to remove the
thought that people might like to know: i found also that imputil, the
standard python module, was lacking the necessary complexity in being
a substitute for the standard __import__ function.
the additions required were very simple:
# note the addition of level=-1 which is ignored
def _i
ng modcompile.py you may be forgiven for going "wtf" but
basically PlatformParser loads the python source; turns it into an
AST; then also the "platform-specific" version is loaded and turned
into an AST; then, the two ASTs are handed to the "merge" function
which does
DG wrote:
There is probably a better way to do this (please enlighten me, if you
know), but what I want to do is get a list of a class' attributes
minus whatever the 'builtin' methods are. I would also like to do
this for instances of classes as well. I don't want to use __dict__
because I want
On Jul 22, 12:24 pm, DG wrote:
> On Jul 22, 12:15 pm, DG wrote:
>
>
>
> > There is probably a better way to do this (please enlighten me, if you
> > know), but what I want to do is get a list of a class' attributes
> > minus whatever the 'builtin' methods are. I would also like to do
> > this fo
On Jul 22, 12:15 pm, DG wrote:
> There is probably a better way to do this (please enlighten me, if you
> know), but what I want to do is get a list of a class' attributes
> minus whatever the 'builtin' methods are. I would also like to do
> this for instances of classes as well. I don't want to
There is probably a better way to do this (please enlighten me, if you
know), but what I want to do is get a list of a class' attributes
minus whatever the 'builtin' methods are. I would also like to do
this for instances of classes as well. I don't want to use __dict__
because I want to get all
me to now read the documentation of "decorators" and
@classmethod and also @staticmethod.
I'm quite new to decorators...
-- Satish BD
On Sun, May 31, 2009 at 4:44 PM, Lie Ryan wrote:
bdsatish wrote:
Hi,
I have a question regarding the difference b/w "class
wrote:
> bdsatish wrote:
>> Hi,
>>
>> I have a question regarding the difference b/w "class methods" and
>> "object methods". Consider for example:
>>
>> class MyClass:
>> x = 10
>>
>> Now I can access MyCla
bdsatish wrote:
> Hi,
>
> I have a question regarding the difference b/w "class methods" and
> "object methods". Consider for example:
>
> class MyClass:
> x = 10
>
> Now I can access MyClass.x -- I want a similar thing for functions. I
&
t, how exactly do I create "class
methods" ??
You mean the classmethod decorator? :)
class MyClass:
@classmethod
def some_func(cls, x):
return x+2
MyClass.some_func(42)
(the decorator syntax was added in 2.4, so if you need it in
pre-2.4, you'd have to
Hi,
I have a question regarding the difference b/w "class methods" and
"object methods". Consider for example:
class MyClass:
x = 10
Now I can access MyClass.x -- I want a similar thing for functions. I
tried
class MyClass:
def some_func(x):
ret
In article <9c848013-2245-455e-bb30-48e430d56...@j9g2000prh.googlegroups.com>,
wrote:
>
>I have a class whose job is to serve several other objects, [...]
Sorry, I'm finding it difficult to understand what you want. It looks
to me that you're confusing "object" and "instance", and I think you'
also no need to have object methods, all could be class
methods (my understanding of benefits between class and objects is not
good, see below).
1. Should I have one object 'O1' that serves all i.e., no class
variables, class methods, if so, since this class is in a module
('M1
> "Emanuele D'Arrigo" (ED) wrote:
>ED> Hi Everybody!
>ED> I just tried this:
> class C(object):
>ED> ...def method(self):
>ED> ...pass
>ED> ...
> c = C()
> delattr(c, "method")
>ED> Traceback (most recent call last):
>ED> File "", line 1, in
>ED> AttributeError: '
Thank you both, Steven and Andrew, for the insightful explanation. I
shall keep it in mind when thinking about classes methods and
instances. Thank you again.
Manu
--
http://mail.python.org/mailman/listinfo/python-list
On Thu, 02 Apr 2009 06:07:20 -0700, Emanuele D'Arrigo wrote:
> Hi Everybody!
>
> I just tried this:
>
class C(object):
> ...def method(self):
> ...pass
> ...
c = C()
delattr(c, "method")
>
> Traceback (most recent call last):
> File "", line 1, in
> AttributeError:
1 - 100 of 291 matches
Mail list logo