Remove spaces and line wraps from html?

Peter Otten __peter__ at web.de
Sat Jun 19 09:39:25 CEST 2004


RiGGa wrote:

> I have just tried your example exacly as you typed
> it (copy and paste) and I get a syntax error everytime
> I run it, it always fails at the line starting:
> 
> def handle_starttag(self, tag, attrs):
> 
> And the error message shown in the command line is:
> 
> DeprecationWarning: Non-ASCII character '\xa0'
> 
> What does this mean?

You get a deprecation warning when your source code contains non-ascii
characters and you have no encoding declared (read the PEP for details).
Those characters have a different meaning depending on the encoding, which
makes the code ambiguous.

However, what's really going on in your case is that (some) space characters
in the source code were replaced by chr(160), which happens sometimes with
newsgroup postings for reasons unknown to me. What makes that nasty is that
chr(160) looks just like the normal space character.

If you run the following from the command line with a space after python
(replace xxx.py with the source file and yyy.py with the name of the new
cleaned-up file), Paramjit's code should work as expected.

python-c'file("yyy.py","w").write(file("xxx.py").read().replace(chr(160),chr(32)))'

Peter




More information about the Python-list mailing list