PEP263 and execfile()

R

Roman Suzi

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

Sincerely yours, Roman Suzi
 
R

Roman Suzi

But is there solution possible without modification of
all those files I do execfile() on?

Sincerely yours, Roman A.Suzi
 
R

Rainer Deyke

Roman said:
But is there solution possible without modification of
all those files I do execfile() on?

Instead of using execfile, you can read the files, add text to them in
memory, and exec the result. Something like this:


def execfile_with_prepend(fname, text_to_prepend):
text = text_to_prepend + open(fname).read()
exec text in {}
 
M

Martin v. =?iso-8859-15?q?L=F6wis?=

Roman Suzi said:
But is there solution possible without modification of
all those files I do execfile() on?

Yes, call warnings.filterwarnings() before calling execfile().

Regards,
Martin
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,566
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top