yEnc implementation in Python, bit slow

Oren Tirosh oren-py-l at hishome.net
Mon Aug 4 17:47:10 EDT 2003


On Tue, Aug 05, 2003 at 12:50:58AM +1000, Freddie wrote:
> Hi,
> 
> I posted a while ago for some help with my word finder program, which is now 
> quite a lot faster than I could manage. Thanks to all who helped :)
> 
> This time, I've written a basic batch binary usenet poster in Python, but 
> encoding the data into yEnc format is fairly slow. Is it possible to improve 
> the routine any, WITHOUT using non-standard libraries? I don't want to have 
> to rely on something strange ;)

Python is pretty quick as long as you avoid loops that operate character
by character. Try to use functions that operate on longer strings.

Suggestions:

For the (x+42)%256 build a translation table and use str.translate.
To encode characters as escape sequences use str.replace or re.sub.

    Oren





More information about the Python-list mailing list