6

Im starting with python and when i use the interpreter and run this code:

>>>peliculas = ["movie1", "movie2", "movie3", "movie4"]
>>>print(peliculas[1])

when i use Pycharm IDE it doesnt compile:

peliculas = ["movie1", "movie2", "movie3", "movie4"]
print(peliculas[1])

This is the output:

 File "/Users/user/PycharmProjects/untitled/Prueba2.py", line 1
SyntaxError: Non-ASCII character '\xc3' in file /Users/user/PycharmProjects/untitled/Prueba2.py on line 1, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details

What´s wrong with python?.. do i installed it correctly?

Charles Duffy
  • 280,126
  • 43
  • 390
  • 441
anon
  • 97
  • 1
  • 2
  • 7
  • 1
    possible duplicate of [Working with utf-8 encoding in Python source](http://stackoverflow.com/questions/6289474/working-with-utf-8-encoding-in-python-source) – Charles Duffy Jul 25 '14 at 01:46
  • 1
    Typing out the whole thing at a stretch. When you copy-paste things in unicode, they stay in unicode, and don't get converted to ASCII. In this case, you have unicode quotes – inspectorG4dget Jul 25 '14 at 01:47
  • I typed everithing, how to fix by default this issue? – anon Jul 25 '14 at 01:51
  • Did you actually _look_ at http://www.python.org/peps/pep-0263.html as the error suggested, before coming here? If not, why not? Maybe you should stop watching those weird Euro-movies with their umlaut-y titles and other funny accented characters, like those in "Óscar López", whose answer you should read :-) – paxdiablo Jul 25 '14 at 01:53
  • @paxdiablo in pycharm? – anon Jul 25 '14 at 01:55
  • 1
    anon, the error has a blink (hey, if everyone else can shorten web-log to blog, surely I can shorten web-link to blink) that it suggests you go look at. You would use a browser for that. – paxdiablo Jul 25 '14 at 01:57

3 Answers3

9

Just add these two lines at to top of python code.

#!/usr/bin/env python
# -*- coding: utf-8 -*- 
Rohit-Pandey
  • 2,039
  • 17
  • 24
7

It's a file encoding problem. Try adding this at the beginning of the file:

#coding=utf-8
Óscar López
  • 232,561
  • 37
  • 312
  • 386
1

In PyCharm you can specify file encoding via the File | File encoding menu, or the file encoding item on the status bar. See this help article