Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #56386
| Date | 2013-10-08 07:07 -0400 |
|---|---|
| From | Ned Batchelder <ned@nedbatchelder.com> |
| Subject | Re: class-private names and the Zen of Python |
| References | <l30lsq$tfd$1@speranza.aioe.org> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.849.1381230484.18130.python-list@python.org> (permalink) |
On 10/8/13 6:13 AM, Marco Buttu wrote:
> In the following case:
>
> >>> class Foo:
> ... _Foo__a = 100
> ... __a = 33
> ...
> >>> Foo._Foo__a
> 33
>
> I think this behavior, for a user who does not know the convention,
> could be a surprise. Should be raising an exception (in order to
> inform the user the transformation of the name __a have been replaced
> an existing name) a possible --explicit-- alternative?
You also get a "problem" if you do this:
>>> class Foo:
... a = 100
... a = 33
...
>>> Foo.a
33
Or for that matter:
>>> a = 100
>>> a = 33
>>> a
33
There are lots of ways to change what value a name refers to, it's not
an error to reassign names.
Also, as Terry mentions, no one has ever assigned the two names you
show, so why try to warn about it?
--Ned.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
class-private names and the Zen of Python Marco Buttu <marco.buttu@gmail.com> - 2013-10-08 12:13 +0200
Re: class-private names and the Zen of Python Terry Reedy <tjreedy@udel.edu> - 2013-10-08 06:36 -0400
Re: class-private names and the Zen of Python Marco Buttu <marco.buttu@gmail.com> - 2013-10-08 12:47 +0200
Re: class-private names and the Zen of Python Ned Batchelder <ned@nedbatchelder.com> - 2013-10-08 07:07 -0400
Re: class-private names and the Zen of Python Marco Buttu <marco.buttu@gmail.com> - 2013-10-08 13:15 +0200
Re: class-private names and the Zen of Python Ned Batchelder <ned@nedbatchelder.com> - 2013-10-08 12:20 -0400
Re: class-private names and the Zen of Python Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-10-08 13:24 +0000
Re: class-private names and the Zen of Python Oscar Benjamin <oscar.j.benjamin@gmail.com> - 2013-10-09 00:00 +0100
Re: class-private names and the Zen of Python Marco Buttu <marco.buttu@gmail.com> - 2013-10-09 07:55 +0200
Re: class-private names and the Zen of Python Charles Hixson <charleshixsn@earthlink.net> - 2013-10-09 12:34 -0700
csiph-web