Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #59908
| Newsgroups | comp.lang.python |
|---|---|
| Date | 2013-11-18 13:02 -0800 |
| References | <b8a1c0cb-a52e-466b-af2a-64059f4e8be3@googlegroups.com> <mailman.2862.1384807451.18130.python-list@python.org> |
| Message-ID | <e90845f9-1908-4a6c-a9d4-e954fc29ed58@googlegroups.com> (permalink) |
| Subject | Re: Why do only callable objects get a __name__? |
| From | John Ladasky <john_ladasky@sbcglobal.net> |
On Monday, November 18, 2013 12:43:28 PM UTC-8, Ian wrote: > Classes and functions are frequently kept in module namespaces, where > they are known by a specific name. The intent is that the __name__ > attribute should match that name by which it is commonly referred. > > > > Specific instances are not typically widely referred to by set names > > in this way. They are more commonly stored in variables that are used > > to hold a wide variety of objects. > > > > In the namedtuple example that you give, it seems that you would want > the names of all instances of the ANamedTuple class to be the same > "ANamedTuple", and I really don't see what the purpose of giving them > all the same name would be. I am implementing a state machine. The outputs of the various states in the machine have variable contents. I started by making dictionaries for each state output, but I soon tired of the bracket-and-quote-mark syntax for referring to the contents of these state output dictionaries. That's why I am switching to named tuples. It doesn't affect the __name__ issue, since dictionaries also cannot be called. I want to capture the names of the executed states in a record of the state machine's history. This information is already encoded in the namedtuple's type. > > 2. If I created a superclass of namedtuple which exposed type(namedtuple).__name__ in the namespace of the namedtuple itself, would I be doing anything harmful? > > Probably not. I just thought I would ask. > But why not just invent your own name attribute rather > than shadow the one that Python designates for classes and functions? I will never write to this attribute, only read it. And since the information I want is already there (albeit in a strange place), I am inclined to use it.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Why do only callable objects get a __name__? John Ladasky <john_ladasky@sbcglobal.net> - 2013-11-18 12:13 -0800
Re: Why do only callable objects get a __name__? John Ladasky <john_ladasky@sbcglobal.net> - 2013-11-18 12:38 -0800
Re: Why do only callable objects get a __name__? Ian Kelly <ian.g.kelly@gmail.com> - 2013-11-18 13:43 -0700
Re: Why do only callable objects get a __name__? John Ladasky <john_ladasky@sbcglobal.net> - 2013-11-18 13:02 -0800
Re: Why do only callable objects get a __name__? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-18 23:37 +0000
Re: Why do only callable objects get a __name__? John Ladasky <john_ladasky@sbcglobal.net> - 2013-11-18 22:10 -0800
Re: Why do only callable objects get a __name__? Terry Reedy <tjreedy@udel.edu> - 2013-11-18 16:11 -0500
Re: Why do only callable objects get a __name__? John Ladasky <john_ladasky@sbcglobal.net> - 2013-11-18 13:26 -0800
Re: Why do only callable objects get a __name__? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-11-18 23:21 +0000
Re: Why do only callable objects get a __name__? John Ladasky <john_ladasky@sbcglobal.net> - 2013-11-18 22:36 -0800
Re: Why do only callable objects get a __name__? Steven D'Aprano <steve@pearwood.info> - 2013-11-19 07:08 +0000
csiph-web