Ask Your Question
2

unicode in doc strings

asked 2011-07-30 13:53:58 +0200

Eugene gravatar image

updated 2011-07-30 13:56:18 +0200

Hi!

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):
        """
        ? ? ? ? ? 
        """
        pass

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

Traceback (most recent call last): File "", line 1, in File "_sage_input_66.py", 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/support.py", line 263, in docstring return html_markup(s) File "/opt/sage/devel/sagenb/sagenb/misc/support.py", 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

Comments

If the thing in the PS happens again, you should feel free to go to askbot.org 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 10:05:44 +0200 )edit
kcrisman gravatar imagekcrisman ( 2015-04-16 16:48:45 +0200 )edit

1 Answer

Sort by ยป oldest newest most voted
2

answered 2011-07-31 21:31:15 +0200

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

Comments

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-08-01 02:52:36 +0200 )edit

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

kcrisman gravatar imagekcrisman ( 2011-08-01 10:04:43 +0200 )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

Stats

Asked: 2011-07-30 13:53:58 +0200

Seen: 1,195 times

Last updated: Jul 31 '11