View Full Version : Problem in Python => comment line interpreted??

April 4th, 2007, 12:18 AM
hi there, I'm just beginning my first steps in programming
I encountered something funny when I ran the program that follows:

#here is something extremely important. First the statements
def imprimdeux(x):
print x + x

# output va Ítre x x
# si on fait imprimdeux('zaille' ou "zaille"), l'imput va Ítre zaille zaille

the program works as "intended" (don't know if that thing can be called a program :p) but I receive the following message in my ouput :

"sys:1: DeprecationWarning: Non-ASCII character '\xc3' in file funcpam.py on line 16, but no encoding declared; see http://www.python.org/peps/pep-0263.html for details"

I thought comments were not supposed to be interpreted by the computer so I wonder what's going on...

Can someone shed some light on this great mystery...?

April 4th, 2007, 12:51 AM
Obviously it checks for UTF encoding before it checks for comments.

April 4th, 2007, 12:54 AM
what's obvious for you isn't obvious for me :)

Care to explain what UTF encoding means?

April 4th, 2007, 01:00 AM
python expects files to be in ascii, if yours is in UTF then you need to start the file with

# -*- coding: UTF-8 -*-


April 4th, 2007, 01:03 AM
many thanks!

April 4th, 2007, 01:05 AM
That may be the problem. But the problem I see is there's no indentation in his example.

#!/usr/bin/env python
def imprimdeux(x):
print x + x
This'll work.

April 4th, 2007, 01:35 AM
The indenting was probably lost when the code was posted to the forum without enclosing it in [ code ] and [ /code ].

April 4th, 2007, 02:48 AM
Just to clarify, the comments are ignored but if any of them got characters that are not in ascii charset, you need to set an encoding at beginning of your .py

April 4th, 2007, 03:44 AM
BTW when I run OP code in IDLE, it suggested correct fix: # -*- coding: UTF-8 -*-

It really helps to use good tools and do not fight them :-)