Results 1 to 9 of 9

Thread: Problem in Python => comment line interpreted??

  1. #1
    Join Date
    Apr 2007
    Beans
    14

    Problem in Python => comment line interpreted??

    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 ) 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...?

  2. #2
    Join Date
    Aug 2006
    Beans
    366

    Re: Problem in Python => comment line interpreted??

    Obviously it checks for UTF encoding before it checks for comments.
    Linux Counter entry # 99383 (since 1995), Feisty Xbuntu 64 bit
    Folders! We don't need no stinking folders. "I don't have anything on my machine that needs folding" -- Unknown

  3. #3
    Join Date
    Apr 2007
    Beans
    14

    Re: Problem in Python => comment line interpreted??

    what's obvious for you isn't obvious for me

    Care to explain what UTF encoding means?

  4. #4
    Join Date
    Dec 2004
    Location
    Manchester
    Beans
    2,086
    Distro
    Ubuntu Mate 15.10 Wily Werewolf

    Re: Problem in Python => comment line interpreted??

    python expects files to be in ascii, if yours is in UTF then you need to start the file with

    Code:
    #!/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/

  5. #5
    Join Date
    Apr 2007
    Beans
    14

    Re: Problem in Python => comment line interpreted??

    many thanks!

  6. #6
    Join Date
    Mar 2007
    Location
    Your Closet
    Beans
    380
    Distro
    Ubuntu 10.04 Lucid Lynx

    Re: Problem in Python => comment line interpreted??

    That may be the problem. But the problem I see is there's no indentation in his example.
    Code:
    #!/usr/bin/env python
    def imprimdeux(x):
    	print x + x
    imprimdeux("x")
    This'll work.
    ...

  7. #7
    WW is offline Iced Blended Vanilla Crème Ubuntu
    Join Date
    Oct 2004
    Beans
    1,532

    Re: Problem in Python => comment line interpreted??

    The indenting was probably lost when the code was posted to the forum without enclosing it in [ code ] and [ /code ].

  8. #8
    Join Date
    Dec 2006
    Beans
    57

    Re: Problem in Python => comment line interpreted??

    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
    -- Guilherme H. Polo Goncalves <ggpolo@gmail.com>

  9. #9
    Join Date
    Jun 2006
    Location
    CT, USA
    Beans
    5,267
    Distro
    Ubuntu 6.10 Edgy

    Re: Problem in Python => comment line interpreted??

    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

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •