469,342 Members | 5,866 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

how to set doc-string of new-style classes

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.

Jul 18 '05 #1
3 1275
harold fellermann <ha***************@upf.edu> 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
Jul 18 '05 #2
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
Jul 18 '05 #3

On 11.01.2005, at 19:35, Alex Martelli wrote:
harold fellermann <ha***************@upf.edu> 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

Jul 18 '05 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by Barry | last post: by
2 posts views Thread by Stu | last post: by
5 posts views Thread by monomaniac21 | last post: by
13 posts views Thread by kbperry | last post: by
13 posts views Thread by LtCommander | last post: by
3 posts views Thread by patrick.waldo | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.