Форум русскоязычного сообщества Ubuntu


Считаете, что Ubuntu недостаточно дружелюбна к новичкам?
Помогите создать новое Руководство для новичков!

Автор Тема: проблема с python в ubuntu 10.04  (Прочитано 4821 раз)

0 Пользователей и 1 Гость просматривают эту тему.

Оффлайн rustam368560

  • Автор темы
  • Новичок
  • *
  • Сообщений: 12
    • Просмотр профиля
Re: проблема с python в ubuntu 10.04
« Ответ #15 : 21 Сентября 2010, 09:38:59 »
почему python не признает символов unicode

Пользователь решил продолжить мысль 21 Сентября 2010, 09:46:42:

SyntaxError: Non-ASCII character '\xd0' in file ./i.py on line 3, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
« Последнее редактирование: 21 Сентября 2010, 09:46:42 от rustam368560 »

Оффлайн blindvic

  • Участник
  • *
  • Сообщений: 179
    • Просмотр профиля
Re: проблема с python в ubuntu 10.04
« Ответ #16 : 21 Сентября 2010, 11:19:58 »
по ссылке же сказано:
Цитировать
Python will default to ASCII as standard encoding if no other encoding hints are given.
питон не знает, что ты написал прогу в кодировке УТФ-8. он думает, что ASCII  - и не может расшифровать некоторые символы.
надо в начале файла указать в он какой кодировке:
# coding=utf-8

Цитировать
To aid with platforms such as Windows, which add Unicode BOM marks to the beginning of Unicode files, the UTF-8 signature '\xef\xbb\xbf' will be interpreted as 'utf-8' encoding as well (even if no magic encoding comment is given).

Оффлайн alexander.pronin

  • Старожил
  • *
  • Сообщений: 2539
    • Просмотр профиля
Re: проблема с python в ubuntu 10.04
« Ответ #17 : 21 Сентября 2010, 13:13:45 »
Точнее так.
# -*- coding: UTF-8 -*-

Оффлайн blindvic

  • Участник
  • *
  • Сообщений: 179
    • Просмотр профиля
Re: проблема с python в ubuntu 10.04
« Ответ #18 : 21 Сентября 2010, 14:56:54 »
Точнее так.
# -*- coding: UTF-8 -*-
и так тоже можно
http://www.python.org/peps/pep-0263.html
Python will default to ASCII as standard encoding if no other
    encoding hints are given.

    To define a source code encoding, a magic comment must
    be placed into the source files either as first or second
    line in the file, such as:

          # coding=<encoding name>

    or (using formats recognized by popular editors)

          #!/usr/bin/python
          # -*- coding: <encoding name> -*-

    or

          #!/usr/bin/python
          # vim: set fileencoding=<encoding name> :

    More precisely, the first or second line must match the regular
    expression "coding[:=]\s*([-\w.]+)". The first group of this
    expression is then interpreted as encoding name. If the encoding
    is unknown to Python, an error is raised during compilation. There
    must not be any Python statement on the line that contains the
    encoding declaration.

 

Страница сгенерирована за 0.018 секунд. Запросов: 22.