module attributes and docstrings

Steven D'Aprano steve+comp.lang.python at pearwood.info
Fri Mar 27 03:31:20 EDT 2015


On Thu, 26 Mar 2015 08:48 pm, Mario Figueiredo wrote:

> Sorry for the late reply. We experienced a 3 day blackout following
> one of the most amazing thunderstorms I've witnessed in my life.

Wow. Where abouts are you? Apart from the blackout, did you get through it
alright?

More below...

> On Tue, 24 Mar 2015 22:49:49 +1100, Steven D'Aprano
> <steve+comp.lang.python at pearwood.info> wrote:
[...]
>>Even if there was support from the compiler to extract the docstring,
>>where would it be stored? Consider:
>>
>>spam = None
>>"""Spammy goodness."""
>>eggs = None
>>"""Scrambled, not fried."""
>>
>>There's only one None object, and even if it could take a docstring (and
>>it can't), which docstring would it get? Presumably the second, which
>>would make help(spam) confusing, but when we say eggs = 23 the docstring
>>would disappear too.
> 
> This is a byproduct of me still thinking in terms of C variables. When
> I first read that paragraph of yours, it didn't make sense to me --
> "What is he talking about? I'm documenting the spam and eggs
> identifiers, not the None object".
> 
> But when I was trying to reply to you by mounting a case around
> writing directly to the __doc__ attribute of the spam and eggs
> identifiers, the python shell was quick to make me realized my
> foolishness, and I remembered about Python variables not being the
> same as C variables.

Yes, that's exactly it!

Some people prefer to say "Python has no variables, it has name bindings". I
think that it's better to say that Python's variables are not *like* C or
Pascal variables, rather than invent a distinction between name bindings
and variables. Name bindings are a type of variable.





-- 
Steven




More information about the Python-list mailing list