how to set doc-string of new-style classes

Discussion in 'Python' started by harold fellermann, Jan 11, 2005.

  1. Hello,

    does anyone know a way to set the __doc__ string of a new style class?
    Any attempt I tried results in the following error:

    Python 2.4 (#1, Dec 30 2004, 08:00:10)
    [GCC 3.3 20030304 (Apple Computer, Inc. build 1495)] on darwin
    Type "help", "copyright", "credits" or "license" for more information.
    >>> class Foo(object) :

    .... pass
    ....
    >>> Foo.__doc__ = "bar"

    Traceback (most recent call last):
    File "<stdin>", line 1, in ?
    TypeError: attribute '__doc__' of 'type' objects is not writable

    I can understand someone arguing that "changing a doc string is during
    programm execution and should therefore be forbidden!" But, I cannot
    even find out a way to set the doc string, when I CREATE a class using
    type(name,bases,dict) ... At least this should be possible, IMHO.

    - harold -

    --
    If you make people think they're thinking, they'll love you;
    but if you really make them think they'll hate you.
     
    harold fellermann, Jan 11, 2005
    #1
    1. Advertising

  2. harold fellermann <> wrote:
    ...
    > But, I cannot
    > even find out a way to set the doc string, when I CREATE a class using
    > type(name,bases,dict) ... At least this should be possible, IMHO.


    >>> x=type('x',(),dict(__doc__='hi there'))
    >>> x.__doc__

    'hi there'



    Alex
     
    Alex Martelli, Jan 11, 2005
    #2
    1. Advertising

  3. harold fellermann

    Peter Otten Guest

    harold fellermann wrote:

    > programm execution and should therefore be forbidden!" But, I cannot
    > even find out a way to set the doc string, when I CREATE a class using
    > type(name,bases,dict) ... At least this should be possible, IMHO.


    That's what the dict parameter is for:

    >>> T = type("T", (object,), dict(__doc__="what you want"))
    >>> T.__doc__

    'what you want'

    Peter
     
    Peter Otten, Jan 11, 2005
    #3
  4. On 11.01.2005, at 19:35, Alex Martelli wrote:

    > harold fellermann <> wrote:
    > ...
    >> But, I cannot
    >> even find out a way to set the doc string, when I CREATE a class using
    >> type(name,bases,dict) ... At least this should be possible, IMHO.

    >
    >>>> x=type('x',(),dict(__doc__='hi there'))
    >>>> x.__doc__

    > 'hi there'


    yes, you're right ... a subsequent question, that puzzles me:
    where can I apply for the "most-stupid-question"-award, now *g*

    thanks anyway,

    - harold -

    --
    The opposite of a correct statement is a false statement.
    But the opposite of a profound truth may be another profound truth.
    -- Niels Bohr
     
    harold fellermann, Jan 11, 2005
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Matt
    Replies:
    3
    Views:
    541
    Tor Iver Wilhelmsen
    Sep 17, 2004
  2. Max Derkachev
    Replies:
    4
    Views:
    689
    Jack Diederich
    May 5, 2005
  3. ankit
    Replies:
    1
    Views:
    362
    Alex Martelli
    Dec 22, 2005
  4. Isaac Rodriguez

    Are all classes new-style classes in 2.4+?

    Isaac Rodriguez, Dec 31, 2006, in forum: Python
    Replies:
    4
    Views:
    398
    Steven D'Aprano
    Dec 31, 2006
  5. Quek
    Replies:
    3
    Views:
    347
Loading...

Share This Page