LoginSignup
6
6

More than 5 years have passed since last update.

#python pythonの日本語のシンタックスエラー回避

Posted at

pythonはじめました。

MacでpyChramを使っています。
環境構築の話などはまた別途。

今回、コードの中で日本語をあつかったら、早速SyntaxErrorにあたりました。

''SyntaxError: Non-ASCII character '\xa3' in file''

日本語を扱う場合は、

  • 文字エンコーディングの宣言を頭でする。
  • 日本語の前に「u」を記述する。
test.py
# -*- coding: utf-8 -*-
__author__ = 'ashibuya'

queries=['Mozart', 'Beethoven','Haydn']
for q in queries:
    print q

queries=[u'モーツァルト', u'ベートーヴェン',u'ハイドン']
for q in queries:
    print q


参考サイト
http://stackoverflow.com/questions/10589620/syntaxerror-non-ascii-character-xa3-in-file-when-function-returns
6
6
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
6
6