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


Groups > comp.lang.python > #59911

Re: Why do only callable objects get a __name__?

Newsgroups comp.lang.python
Date 2013-11-18 13:26 -0800
References <b8a1c0cb-a52e-466b-af2a-64059f4e8be3@googlegroups.com> <mailman.2865.1384809081.18130.python-list@python.org>
Message-ID <8e48ff5d-81fb-47ef-96b0-7484d2cbab3d@googlegroups.com> (permalink)
Subject Re: Why do only callable objects get a __name__?
From John Ladasky <john_ladasky@sbcglobal.net>

Show all headers | View raw


On Monday, November 18, 2013 1:11:08 PM UTC-8, Terry Reedy wrote:
> On 11/18/2013 3:13 PM, John Ladasky wrote:
> 
> > Of course, I have used __name__ for years in the common expression "if __name__ == '__main__'") to determine whether a particular module is being run or merely imported.
> 
> This true statement invalidates your subject line ;-). All modules have 
> a __name__. 

Yes, I thought about this before I posted.  I figured that, if I investigated further I would discover that there was a __main__ function that was being called.

> > 1. WHY do only callable objects get a __name__?
> 
> Why do you think this? Is there a mistake in the doc?

Quote below from http://docs.python.org/3/reference/datamodel.html:

=======================================================================

Callable types
These are the types to which the function call operation (see section Calls) can be applied:

User-defined functions
A user-defined function object is created by a function definition (see section Function definitions). It should be called with an argument list containing the same number of items as the function’s formal parameter list.

Special attributes:

Attribute	Meaning
__name__	The function’s name	Writable

=======================================================================

Perhaps I'm inferring too much from slightly-vague documentation, and my recent experience with objects that cannot be called?  Or perhaps the information that I need to read is somewhere in the documentation other than where I have looked?

Still puzzling over this...  I can easily hack a solution as Terry suggested, but it's not elegant, and that kind of thing bugs me.

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


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