PDA

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



gammaknife
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
imprimdeux("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...?

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

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

Care to explain what UTF encoding means?

ssam
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


#!/usr/bin/python
# -*- coding: UTF-8 -*-


http://en.wikipedia.org/wiki/Unicode
http://en.wikipedia.org/wiki/Ascii
http://www.python.org/dev/peps/pep-0263/

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

bashologist
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
imprimdeux("x")
This'll work.

WW
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 ].

gpolo
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

pmasiar
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 :-)