the address of list.append and list.append.__doc__

Gabriel Genellina gagsl-py2 at yahoo.com.ar
Wed Sep 26 02:57:18 EDT 2007


En Wed, 26 Sep 2007 03:29:09 -0300, HYRY <ruoyu0088 at gmail.com> escribi�:

> I want to add a docstring translator into the Python interpreter. If
> the user input:
>>>> a = [1,2,3]
>>>> a.append(
> this translator will show the docstring of append in my native
> language. Because __doc__ is read only, I added a dict to the
> interpreter as follows:
>
> DOC[list.append.__doc__] = """ translated version of the __doc__ """
>
> When it is the time to show docstring, the program get the translated
> version from DOC.
> This works, but I think the key of DOC is too long, so I want to use
> the id of list.append.__doc__ as the key; or use the id of
> list.append:

Don't worry about that. There is no "wasted memory" apart from some  
overhead due to the string object itself (a few bytes per string, fixed  
and not depending on the string length).
Just use the __doc__ as the dictionary key. Perhaps using an external  
database, to avoid keeping all the translated texts in memory.

-- 
Gabriel Genellina




More information about the Python-list mailing list