PEP263 and execfile()

Mike C. Fletcher mcfletch at rogers.com
Mon Nov 17 14:56:06 EST 2003


Roman Suzi wrote:

>hi!
>
>One of my old web projects uses execfile alot, because
>its data are stored in Python. How do I suppress
>all those warnings
>
>DeprecationWarning: Non-ASCII character '\xd2' in file ffff.py on line 5,
>but no encoding declared; see http://www.python.org/peps/pep-0263.html for details
>
>in one place (preferably at execfile() call)?
>  
>
Ran into the same problem with ResourcePackage (which stores binary data 
in Python files).  I put a dumb (i.e. solely to shut up the system) 
encoding declaration (a (meaningless) declaration that the file use some 
arbitrary 8-bit encoding, such as latin-1 so that high-bit characters 
are acceptable) at the top of the files (i.e. modified the system to 
write those encodings on storage). 

In your case you'd need to write a script to fix up all the old files 
(luckily they'll all be on your web-server) too.

# -*- coding: ISO-8859-1 -*-

for file in files:
    open(file, 'w').write( HEADER+ open(file,'r').read())

(though, of course, you'd want to be a little more careful than that ;) ).

Good luck, and HTH,
Mike

_______________________________________
  Mike C. Fletcher
  Designer, VR Plumber, Coder
  http://members.rogers.com/mcfletch/








More information about the Python-list mailing list