By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,550 Members | 1,189 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,550 IT Pros & Developers. It's quick & easy.

how to set doc-string of new-style classes

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a

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.