Bug? import cp1252

Discussion in 'Python' started by Méta-MCI, May 12, 2007.

  1. Méta-MCI

    Méta-MCI Guest

    Hi!

    I've a problem with these 2 scripts:


    file aaa.py (write in ANSI/cp1252):

    # -*- coding: cp1252 -*-

    compo={}

    compo['pxrtf']= {
    'fichier': "pxrtf.py",
    'description': "Génération de fichiers RTF"
    }



    file bbb.py (write in ANSI/cp1252):

    # -*- coding: cp1252 -*-

    import aaa



    With run bbb.py, I see:

    Traceback (most recent call last):
    File "D:\dev\python\bbb.py", line 3, in <module>
    import aaa
    File "D:\dev\python\aaa.py", line 3

    ^
    SyntaxError: invalid syntax



    (run directly aaa.py give no problem)


    (Python 2.5.1 + win_XP-SP2_french)




    BUT, if I write the file aaa.py in UTF-8, with 1st line: # -*- coding:
    utf-8 -*-
    the problem is removed (file bbb.py stay in ANSI/cp1252)



    Bug? or am I wrong?



    @-salutations

    Michel Claveau
     
    Méta-MCI, May 12, 2007
    #1
    1. Advertising

  2. Méta-MCI

    John Machin Guest

    Re: Bug? import cp1252

    On May 13, 3:33 am, "Méta-MCI" <>
    wrote:
    > Hi!
    >
    > I've a problem with these 2 scripts:
    >
    > file aaa.py (write in ANSI/cp1252):


    What is "ANSI/cp1252"???

    >
    > # -*- coding: cp1252 -*-
    >
    > compo={}
    >
    > compo['pxrtf']= {
    > 'fichier': "pxrtf.py",
    > 'description': "Génération de fichiers RTF"
    > }
    >
    > file bbb.py (write in ANSI/cp1252):
    >
    > # -*- coding: cp1252 -*-
    >
    > import aaa
    >
    > With run bbb.py, I see:
    >
    > Traceback (most recent call last):
    > File "D:\dev\python\bbb.py", line 3, in <module>
    > import aaa
    > File "D:\dev\python\aaa.py", line 3
    >
    > ^
    > SyntaxError: invalid syntax
    >
    > (run directly aaa.py give no problem)
    >
    > (Python 2.5.1 + win_XP-SP2_french)
    >
    > BUT, if I write the file aaa.py in UTF-8, with 1st line: # -*- coding:
    > utf-8 -*-
    > the problem is removed (file bbb.py stay in ANSI/cp1252)
    >
    > Bug? or am I wrong?
    >
    > @-salutations
    >


    Michel, I can't reproduce this -- Python 2.5.1, Windows XP Pro SP2

    Given that the syntax error seems to be pointing to a blank empty
    line, I suspect that's there's some invisible character in the file.
    This would be likely not to show up when we view your file through a
    web browser or news client. I suggest that you show us *exactly* what
    you've got:

    print open('aaa.py', 'rb').read()

    HTH,
    John
     
    John Machin, May 13, 2007
    #2
    1. Advertising

  3. Méta-MCI

    Méta-MCI Guest

    Re: Bug? import cp1252

    Hi!

    >>> I suspect that's there's some invisible character in the file


    No ; because I reproduce the problem, on another CPU, with typing from
    scratch.



    >>> I can't reproduce this -- Python 2.5.1, Windows XP Pro SP2


    I'm sorry. Perhaps my "french" windows is a co-factor?
    Perhaps my locale has Or my local influence?

    I had try on four computer, with the same problem.



    Fortunately, write in UTF-8 delete the problem...


    --
    Michel Claveau
     
    Méta-MCI, May 14, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Mickey Segal
    Replies:
    5
    Views:
    33,598
    Mickey Segal
    Apr 20, 2005
  2. David Eppstein

    Distinguishing cp850 and cp1252?

    David Eppstein, Nov 3, 2003, in forum: Python
    Replies:
    3
    Views:
    615
    David Eppstein
    Nov 3, 2003
  3. Do Re Mi chel La Si Do

    To circumvent the bug cp1252

    Do Re Mi chel La Si Do, May 15, 2005, in forum: Python
    Replies:
    0
    Views:
    432
    Do Re Mi chel La Si Do
    May 15, 2005
  4. =?iso-8859-1?B?bW9vcJk=?=

    Cp1252 problem

    =?iso-8859-1?B?bW9vcJk=?=, Sep 27, 2006, in forum: Java
    Replies:
    2
    Views:
    41,149
    Mike Schilling
    Sep 27, 2006
  5. Replies:
    12
    Views:
    413
    Dennis Lee Bieber
    Nov 18, 2012
Loading...

Share This Page