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?

6
  • 1
    possible duplicate of Working with utf-8 encoding in Python source Commented Jul 25, 2014 at 1: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 Commented Jul 25, 2014 at 1:47
  • I typed everithing, how to fix by default this issue? Commented Jul 25, 2014 at 1:51
  • Did you actually look at 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 :-) Commented Jul 25, 2014 at 1:53
  • 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. Commented Jul 25, 2014 at 1:57

3 Answers 3

9

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

#!/usr/bin/env python
# -*- coding: utf-8 -*- 
Sign up to request clarification or add additional context in comments.

Comments

7

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

#coding=utf-8

1 Comment

or # -*- coding: utf-8 -*-
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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.