Ask Your Question

unicode in doc strings

asked 2011-07-30 06:53:58 -0500

Eugene gravatar image

updated 2011-07-30 06:56:18 -0500


Is it possible to use utf-8 characters in doc-strings? I tried to write description to __init__ method in russian language:

class Bazz:
    def __init__(self):
        ? ? ? ? ? 

but then I write "Bazz(" and press tab:

Traceback (most recent call last): File "", line 1, in File "", line 10, in exec compile(u'print _support_.docstring("Bazz", globals(), system="sage")' + '\n', '', 'single') File "", line 1, in File "/opt/sage/devel/sagenb/sagenb/misc/", line 263, in docstring return html_markup(s) File "/opt/sage/devel/sagenb/sagenb/misc/", line 288, in html_markup return '

' + preamble + '

' + s + '

' UnicodeDecodeError: 'ascii' codec can't decode byte 0xd0 in position 11: ordinal not in range(128)

P.S. After I posted this question, site relapsed russian characters in code with '?' :-\

edit retag flag offensive close merge delete


If the thing in the PS happens again, you should feel free to go to and see about this; I am pretty sure the developer of askbot would be interested in making sure this works - perhaps via some preamble, I don't know.

kcrisman gravatar imagekcrisman ( 2011-08-01 03:05:44 -0500 )edit
kcrisman gravatar imagekcrisman ( 2015-04-16 09:48:45 -0500 )edit

1 answer

Sort by ยป oldest newest most voted

answered 2011-07-31 14:31:15 -0500

Have you tried putting

# -*- coding: utf-8 -*-

as the very first line of your file? You might also try replacing the """ at the start of the docstring with u""" or with ur""".

edit flag offensive delete link more


Yep, I tried to insert '# -*- coding: utf-8 -*-' into the first cell of notebook, then I moved class definition to file with '# -*- coding: utf-8 -*-' in the beginning and loaded it with 'load' command. The same exception appears in both cases.

Eugene gravatar imageEugene ( 2011-07-31 19:52:36 -0500 )edit

What about the other suggestion? That would seem more likely to me to work.

kcrisman gravatar imagekcrisman ( 2011-08-01 03:04:43 -0500 )edit

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools


Asked: 2011-07-30 06:53:58 -0500

Seen: 844 times

Last updated: Jul 31 '11