How to draw Arabic lines in Bottle format?

I am learning the Bottle framework and a new one for Python. Just stumbled upon this difficulty. When I write a simple method to return an Arabic string, for example:

@route('/hello')
def hello():
    return u'ุณู„ุงู…'

I get this error message in terminal:

Syntax Error: non-ASCII character '\ xd8' in the hello.py file on line 15, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

I imported everything from the bottle and tried to add other methods mentioned in the docs where it talks about โ€œChanging the default encodingโ€ I could not solve the problem. Therefore, I appreciate your hints.

+5
source share
4

:

#!/usr/bin/env python
# -*- coding: utf-8 -*-

from bottle import *

@route('/hello')
def hello():
    return u'ุณู„ุงู…'

run(host='127.0.0.1', port=8080,reloader=True)

"" > " ...", "" (UTF-8) " " hello.py

bottle.py github (, ) .

, , .

~$ python --version
Python 2.6.7
~$ cd bottle-test
bottle-test$ python hello.py 

Result in browser

+7

# -*- coding: whatever-encoding-you-use -*-

+5

Save the file as utf-8 and paste

#encoding: utf-8

as the first line of your file

+2
source

At the top of your script, type the following:

# encoding: utf-8

The fact is that your script can work with the encoding latin1 (ISO 8859-1), which is limited compared to UTF-8

+2
source

All Articles