Re: Typing on child class' methods of a Generic base class

2022-03-12 Thread Dieter Maurer
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 >>>

Re: Typing on child class' methods of a Generic base class

2022-03-12 Thread Nicolas Haller
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

Re: Typing on child class' methods of a Generic base class

2022-03-10 Thread Dieter Maurer
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.

Typing on child class' methods of a Generic base class

2022-03-09 Thread Nicolas Haller
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

Pytest share fixture data across the class methods

2019-06-26 Thread Arup Rakshit
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

Re: Writing SOME class methods in C

2015-11-29 Thread Stefan Behnel
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 >>

Re: Writing SOME class methods in C

2015-11-18 Thread Oscar Benjamin
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). >

Re: Writing SOME class methods in C

2015-11-18 Thread Terry Reedy
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

Writing SOME class methods in C

2015-11-17 Thread Daniel Haude
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

Re: Understanding decorator and class methods

2014-01-08 Thread Terry Reedy
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)

Re: Understanding decorator and class methods

2014-01-08 Thread Rotwang
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

Understanding decorator and class methods

2014-01-08 Thread axis . of . weasel
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)

Re: Context manager with class methods

2011-09-23 Thread Gregory Ewing
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

Re: Context manager with class methods

2011-09-22 Thread Terry Reedy
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):

Re: Context manager with class methods

2011-09-22 Thread Mel
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

Re: Context manager with class methods

2011-09-22 Thread Mel
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): >

Re: Context manager with class methods

2011-09-22 Thread Thomas Rachel
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):

Context manager with class methods

2011-09-22 Thread 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): print("__exit__") with Foo

Re: Why do class methods always need 'self' as the first parameter?

2011-09-07 Thread Piet van Oostrum
"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

Re: Why do class methods always need 'self' as the first parameter?

2011-09-05 Thread Steven D'Aprano
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

Re: Why do class methods always need 'self' as the first parameter?

2011-09-05 Thread rantingrick
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

Re: Why do class methods always need 'self' as the first parameter?

2011-09-05 Thread Chris Torek
>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

Re: Why do class methods always need 'self' as the first parameter?

2011-09-05 Thread Piet van Oostrum
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

Re: Why do class methods always need 'self' as the first parameter?

2011-09-02 Thread John Roth
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

Re: Why do class methods always need 'self' as the first parameter?

2011-09-02 Thread Ian Kelly
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

Re: Why do class methods always need 'self' as the first parameter?

2011-09-02 Thread John Roth
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 >

Re: Why do class methods always need 'self' as the first parameter?

2011-09-01 Thread Ian Kelly
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

Re: Why do class methods always need 'self' as the first parameter?

2011-09-01 Thread John Roth
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'

Re: Why do class methods always need 'self' as the first parameter?

2011-09-01 Thread Michiel Overtoom
> 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

Re: Why do class methods always need 'self' as the first parameter?

2011-09-01 Thread UncleLaz
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'

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Chris Torek
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Eric Snow
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Chris Angelico
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Steven D'Aprano
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Terry Reedy
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)

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Ian Kelly
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Chris Torek
>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$

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Chris Rebert
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

RE: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Prasad, Ramit
>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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Terry Reedy
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Grant Edwards
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?

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Steven D'Aprano
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Steven D'Aprano
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Javier Collado
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Neil Cerutti
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread Emile van Sebille
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

Re: Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread John Gordon
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

Why do class methods always need 'self' as the first parameter?

2011-08-31 Thread T. Goodchild
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

Re: My stupidity / strange inconsistency overriding class methods

2011-04-20 Thread andrew cooke
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

Re: My stupidity / strange inconsistency overriding class methods

2011-04-20 Thread andrew cooke
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

Re: My stupidity / strange inconsistency overriding class methods

2011-04-19 Thread Chris Rebert
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

Re: My stupidity / strange inconsistency overriding class methods

2011-04-19 Thread andrew cooke
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

Re: My stupidity / strange inconsistency overriding class methods

2011-04-19 Thread andrew cooke
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

My stupidity / strange inconsistency overriding class methods

2011-04-19 Thread andrew cooke
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

Re: How can I define class methods outside of the class?

2010-12-02 Thread Jeremy
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

Re: How can I define class methods outside of the class?

2010-12-02 Thread bruno.desthuilli...@gmail.com
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

Re: How can I define class methods outside of the class?

2010-12-02 Thread bruno.desthuilli...@gmail.com
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&

Re: How can I define class methods outside of the class?

2010-12-02 Thread Jeremy
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

Re: How can I define class methods outside of the class?

2010-12-01 Thread Ian Kelly
, 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

Re: How can I define class methods outside of the class?

2010-12-01 Thread James Mills
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

How can I define class methods outside of the class?

2010-12-01 Thread Jeremy
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

Re: Referring to class methods in class attributes

2010-02-18 Thread Bruno Desthuilliers
, 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__.

Re: Referring to class methods in class attributes

2010-02-18 Thread Steve Holden
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

Re: Referring to class methods in class attributes

2010-02-18 Thread mk
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

Re: Referring to class methods in class attributes

2010-02-18 Thread Bruno Desthuilliers
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:/

Re: Referring to class methods in class attributes

2010-02-18 Thread Ben Finney
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/>.

Re: Referring to class methods in class attributes

2010-02-18 Thread mk
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

Re: Referring to class methods in class attributes

2010-02-18 Thread Bruno Desthuilliers
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

Re: Referring to class methods in class attributes

2010-02-17 Thread Mark Lawrence
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

Re: Referring to class methods in class attributes

2010-02-17 Thread Ben Finney
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,

Re: Referring to class methods in class attributes

2010-02-17 Thread Bruno Desthuilliers
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,

Re: Referring to class methods in class attributes

2010-02-17 Thread Arnaud Delobelle
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

Re: Referring to class methods in class attributes

2010-02-17 Thread John Posner
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

Re: Referring to class methods in class attributes

2010-02-17 Thread Bruno Desthuilliers
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

Re: Referring to class methods in class attributes

2010-02-17 Thread Jean-Michel Pichavant
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

Re: Referring to class methods in class attributes

2010-02-17 Thread Stephen Hansen
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

Re: Referring to class methods in class attributes

2010-02-17 Thread mk
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

Re: Referring to class methods in class attributes

2010-02-17 Thread Stephen Hansen
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

Referring to class methods in class attributes

2010-02-17 Thread mk
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'

Re: platform-specific overrides of functions and class methods (expanding on imputils demo code)

2009-09-14 Thread lkcl
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 > >

Re: platform-specific overrides of functions and class methods (expanding on imputils demo code)

2009-09-12 Thread Aahz
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

Re: platform-specific overrides of functions and class methods (expanding on imputils demo code)

2009-09-06 Thread Terry Reedy
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

Re: platform-specific overrides of functions and class methods (expanding on imputils demo code)

2009-09-06 Thread lkcl
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

Re: platform-specific overrides of functions and class methods (expanding on imputils demo code)

2009-08-20 Thread Aahz
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

Re: platform-specific overrides of functions and class methods (expanding on imputils demo code)

2009-08-17 Thread lkcl
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

platform-specific overrides of functions and class methods (expanding on imputils demo code)

2009-08-16 Thread lkcl
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

Re: list of 'magic methods' or builtin class methods... want to exclude those from dir output

2009-07-22 Thread Terry Reedy
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

Re: list of 'magic methods' or builtin class methods... want to exclude those from dir output

2009-07-22 Thread DG
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

Re: list of 'magic methods' or builtin class methods... want to exclude those from dir output

2009-07-22 Thread DG
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

list of 'magic methods' or builtin class methods... want to exclude those from dir output

2009-07-22 Thread DG
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

Re: Class Methods help

2009-06-01 Thread Jean-Michel Pichavant
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

Re: Class Methods help

2009-05-31 Thread bd satish
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

Re: Class Methods help

2009-05-31 Thread Lie Ryan
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 &

Re: Class Methods help

2009-05-31 Thread Tim Chase
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

Class Methods help

2009-05-31 Thread bdsatish
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

Re: class variables and class methods

2009-04-18 Thread Aahz
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'

class variables and class methods

2009-04-17 Thread krishnapostings
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&#

Re: Class methods read-only by default?

2009-04-03 Thread Piet van Oostrum
> "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: '

Re: Class methods read-only by default?

2009-04-03 Thread Emanuele D'Arrigo
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

Re: Class methods read-only by default?

2009-04-02 Thread Steven D'Aprano
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   2   3   >