Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Bug? import cp1252

Reply
Thread Tools

Bug? import cp1252

 
 
Méta-MCI
Guest
Posts: n/a
 
      05-12-2007
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



 
Reply With Quote
 
 
 
 
John Machin
Guest
Posts: n/a
 
      05-12-2007
On May 13, 3:33 am, "Méta-MCI" <(E-Mail Removed)>
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

 
Reply With Quote
 
 
 
 
Méta-MCI
Guest
Posts: n/a
 
      05-14-2007
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


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
latin1 and cp1252 inconsistent? buck@yelp.com Python 12 11-18-2012 06:48 AM
Cp1252 problem =?iso-8859-1?B?bW9vcJk=?= Java 2 09-27-2006 02:20 PM
To circumvent the bug cp1252 Do Re Mi chel La Si Do Python 0 05-15-2005 11:51 AM
Is the default Java character encoding always Cp1252? Mickey Segal Java 5 04-20-2005 04:16 PM
Distinguishing cp850 and cp1252? David Eppstein Python 3 11-03-2003 05:47 AM



Advertisments