Re: PEP263 and execfile()

From: Mike C. Fletcher (mcfletch_at_rogers.com)
Date: 11/17/03


Date: Mon, 17 Nov 2003 14:56:06 -0500
To: Roman Suzi <rnd@onego.ru>

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/



Relevant Pages

  • Re: a question about Chinese characters in a Python Program
    ... Normally I'd entertain the possibility of bugs in Python, ... and that you indicate how the Unicode values are encoded as ... bytes (by specifying an encoding). ... EVERY SINGLE character expression with try ... ...
    (comp.lang.python)
  • Re: a question about Chinese characters in a Python Program
    ... Python encoding. ... characters, but I've seen public advertisements (admittedly aimed at ... But it's tiring in python to deal with encodings, ... Unicode character to a byte value using the ASCII character value ...
    (comp.lang.python)
  • ANN: cssutils 0.9.5final
    ... A Python package to parse and build CSS Cascading Style Sheets. ... encodings should keep the encoding as defined now. ... ``cssutils.script.csscombine`` and ``csscombine`` script do use the cssutils log now instead of just writing messages to ``sys.stderr`` ...
    (comp.lang.python.announce)
  • Re: Python and decimal character entities over 128.
    ... the string "doesn't" may be coded as ... Python hates decimal entities beyond 128 so it chokes unless you do ... Web sites may use whatever encoding they please. ... Decode ignoring those character that cannot be decoded. ...
    (comp.lang.python)
  • Re: How do I get unicode support in python?
    ... unable to print any characters outside of ascii. ... What do I need to do to get python on the web server to have unicode ... For Python to be able to "print" unicode characters to the console, ... know the encoding of the console. ...
    (freebsd-questions)