Ask Your Question
2

unicode in doc strings

asked 13 years ago

Eugene gravatar image

updated 13 years ago

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 '?' :-\

Preview: (hide)

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 ( 13 years ago )

1 Answer

Sort by » oldest newest most voted
2

answered 13 years ago

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""".

Preview: (hide)
link

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 ( 13 years ago )

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

kcrisman gravatar imagekcrisman ( 13 years ago )

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: 13 years ago

Seen: 1,275 times

Last updated: Jul 31 '11