Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #76780

when the method __get__ will be called?

Date 2014-08-22 15:08 +0800
From luofeiyu <elearn2014@gmail.com>
Subject when the method __get__ will be called?
Newsgroups comp.lang.python
Message-ID <mailman.13278.1408691339.18130.python-list@python.org> (permalink)

Show all headers | View raw


class C(object):
     a = 'abc'
     def __getattribute__(self, *args, **kwargs):
         print("__getattribute__() is called")
         return object.__getattribute__(self, *args, **kwargs)
     def __getattr__(self, name):
         print("__getattr__() is called ")
         return name + " from getattr"
     def __get__(self, instance, owner):
         print("__get__() is called", instance, owner)
         return self
     def foo(self, x):
         print(x)


 >>> x=C()
 >>> x.a
__getattribute__() is called
'abc'
 >>> x.b
__getattribute__() is called
__getattr__() is called
'b from getattr'




If call an attribute which does exist ,__getattribute__() is called
If call an attribute which does not  exist ,__getattribute__() is called
and then __getattr__() is called ?

when the __get__ method will be called?no chance for my example?

Back to comp.lang.python | Previous | NextNext in thread | Find similar | Unroll thread


Thread

when the method  __get__  will be called? luofeiyu <elearn2014@gmail.com> - 2014-08-22 15:08 +0800
  Re: when the method  __get__  will be called? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-08-22 17:30 +1000

csiph-web