why python is slower than java?
Alex Martelli
aleaxit at yahoo.com
Sun Nov 7 10:44:28 EST 2004
Pythogoras <noreal at email.org> wrote:
> But maybe you want to have something more fun?
> How about that?
> read autoexec.bat,
> sort the lines
> create sorted_autoexec.bak
file('sorted_autoexec.bak','w').writelines(sorted(file('autoexec.bat')))
73 chars in one line. Yeah, I cheated -- I _would_ normally put a space
after the comma, making the real total into seventyFOUR...
>
> ///
> File source = new File("c:/autoexec.bat");
> File destination = new File("c:/sorted_autoexec.bak");
>
> String[] lines = readLines(source);
> lines = sort(lines);
> write(destination,lines);
How delightfully quaint and redundant. I do recall a time where Python
would take such a roundabout approach too -- of course, the Python code,
even at that time, was elegantly object-oriented, with the reading,
sorting and writing all neatly expressed as methods of file and list
objects, rather than these weird 'readLines' and 'sort' and 'write'
apparently-global functions taking the objects as arguments. Still, all
of those mysterious 'globals' does enhance the retrocomputing taste of
your code -- one can almost see you writing it with a quill dipped in
ink, at a carved oak desk, on your steam-powered computer. Charming!
Should you ever decide to move into the 21st century, though, don't
worry: Python will be there to help you do so.
Alex
More information about the Python-list
mailing list