Re: how to get names of attributes

2015-12-31 Thread Charles T. Smith
On Thu, 31 Dec 2015 10:58:17 +1100, Steven D'Aprano wrote: (some very good information) Thank you. -- https://mail.python.org/mailman/listinfo/python-list

Re: how to get names of attributes

2015-12-30 Thread Steven D'Aprano
On Wed, 30 Dec 2015 10:51 pm, Charles T. Smith wrote: > Hi, > > How can I get *all* the names of an object's attributes? In the most general case, you cannot. Classes can define a __getattr__ method (and a __getattribute__ method, for new-style classes only) which implement dynamic attributes

Re: how to get names of attributes

2015-12-30 Thread Chris Angelico
On Thu, Dec 31, 2015 at 4:04 AM, Random832 wrote: > On Wed, Dec 30, 2015, at 07:50, Chris Angelico wrote: >> I believe that's true, yes. The meaning of "by default" there is that >> "class X: pass" will make an old-style class. All built-in types are >> now new-style classes. > > To be clear, AFAI

Re: how to get names of attributes

2015-12-30 Thread Random832
On Wed, Dec 30, 2015, at 07:50, Chris Angelico wrote: > I believe that's true, yes. The meaning of "by default" there is that > "class X: pass" will make an old-style class. All built-in types are > now new-style classes. To be clear, AFAIK, built-in types were never old-style classes - prior to t

Re: how to get names of attributes

2015-12-30 Thread Charles T. Smith
On Wed, 30 Dec 2015 14:10:14 +, Mark Lawrence wrote: > On 30/12/2015 11:51, Charles T. Smith wrote: >> Hi, >> >> Does anyone know *why* the __members__ method was deprecated, to be >> replaced by dir(), which doesn't tell the truth (if only it took an >> optional parameter to say: "be truthful

Re: how to get names of attributes

2015-12-30 Thread Chris Angelico
On Thu, Dec 31, 2015 at 12:31 AM, Charles T. Smith wrote: > Okay, thank you. I'm trying to understand your program. > > Unfortunately, I haven't gotten the same output you had, using python 2.6 > or 2.7. Maybe I haven't been able to restore the indentation correctly > after having been filtered

Re: how to get names of attributes

2015-12-30 Thread Mark Lawrence
On 30/12/2015 13:31, Charles T. Smith wrote: I wonder what the difference is between vars() and items() Not much. From https://docs.python.org/3/library/functions.html#vars vars([object]) Return the __dict__ attribute for a module, class, instance, or any other object with a __dict__

Re: how to get names of attributes

2015-12-30 Thread Mark Lawrence
On 30/12/2015 11:51, Charles T. Smith wrote: Hi, Does anyone know *why* the __members__ method was deprecated, to be replaced by dir(), which doesn't tell the truth (if only it took an optional parameter to say: "be truthful") https://bugs.python.org/issue456420 https://bugs.python.org/issue44

Re: how to get names of attributes

2015-12-30 Thread Charles T. Smith
On Wed, 30 Dec 2015 23:50:03 +1100, Chris Angelico wrote: > On Wed, Dec 30, 2015 at 11:40 PM, Charles T. Smith > wrote: >> Oh! >> >> Although the referenced doc says: >> >> "For compatibility reasons, classes are still old-style by default." >> >> is it true that dictionaries are by default alw

Re: how to get names of attributes

2015-12-30 Thread Chris Angelico
On Wed, Dec 30, 2015 at 11:40 PM, Charles T. Smith wrote: > Oh! > > Although the referenced doc says: > > "For compatibility reasons, classes are still old-style by default." > > is it true that dictionaries are by default always new-style objects? > > (PDB)c6 = { "abc" : 123, "def" : 456} > >

Re: how to get names of attributes

2015-12-30 Thread Charles T. Smith
On Wed, 30 Dec 2015 11:51:19 +, Charles T. Smith wrote: > Hi, > > How can I get *all* the names of an object's attributes? I have legacy > code with mixed new style classes and old style classes and I need to > write methods which deal with both. That's the immediate problem, but > I'm alwa

Re: how to get names of attributes

2015-12-30 Thread Chris Angelico
On Wed, Dec 30, 2015 at 11:16 PM, Charles T. Smith wrote: > I'm glad I discovered __mro__(), but how can I do the same thing for old- > style classes? You should be able to track through __bases__ and use vars() at every level: >>> class X: pass ... >>> class Y(X): pass ... >>> class Z(Y): pass

Re: how to get names of attributes

2015-12-30 Thread Charles T. Smith
On Wed, 30 Dec 2015 11:51:19 +, Charles T. Smith wrote: > Hi, > > How can I get *all* the names of an object's attributes? I have legacy > code with mixed new style classes and old style classes and I need to > write methods which deal with both. That's the immediate problem, but > I'm alwa

Re: how to get names of attributes

2015-12-30 Thread Chris Angelico
On Wed, Dec 30, 2015 at 10:51 PM, Charles T. Smith wrote: > Does anyone know *why* the __members__ method was deprecated, to be > replaced by dir(), which doesn't tell the truth (if only it took an > optional parameter to say: "be truthful") Does vars() help here? It works on old-style and new-st