On Tue, 21 Aug 2012 09:44:10 -0700, Miki Tebeka wrote:

> Greetings,
> 
>>>> class A:
> ...     '''a doc string'''
> ...
>>>> A.__doc__
> 'a doc string'
>>>> class B:
> ...     '''a {} string'''.format('doc') ...
>>>> B.__doc__
>>>> 
>>>> 
> Is there's a reason for this?

Yes. Python only generates docstrings automatically from string literals, 
not arbitrary expressions.

Arbitrary expressions are evaluated and then garbage collected, so:

class B:
    '''a {} string'''.format('doc')

is equivalent to:

class B:
    __doc__ = None
    _tmp = '''a {} string'''.format('doc')
    del _tmp

except that the name "_tmp" doesn't actually get used.



-- 
Steven
-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to