Speed ain't bad
Bulba!
bulba at bulba.com
Sun Jan 2 13:39:30 EST 2005
On Sat, 1 Jan 2005 14:20:06 +0100, "Anders J. Munch"
<andersjm at inbound.dk> wrote:
>> One of the posters inspired me to do profiling on my newbie script
>> (pasted below). After measurements I have found that the speed
>> of Python, at least in the area where my script works, is surprisingly
>> high.
>
>Pretty good code for someone who calls himself a newbie.
<blush>
>One line that puzzles me:
>> sfile=open(sfpath,'rb')
>You never use sfile again.
Right! It's a leftover from a previous implementation (that
used bzip2). Forgot to delete it, thanks.
>Another way is the strategy of "it's easier to ask forgiveness than to
>ask permission".
>If you replace:
> if(not os.path.isdir(zfdir)):
> os.makedirs(zfdir)
>with:
> try:
> os.makedirs(zfdir)
> except EnvironmentError:
> pass
>then not only will your script become a micron more robust, but
>assuming zfdir typically does not exist, you will have saved the call
>to os.path.isdir.
Yes, this is the kind of habit that low-level languages like C
missing features like exceptions ingrain in a mind of a programmer...
Getting out of this straitjacket is kind of hard - it would not cross
my mind to try smth like what you showed me, thanks!
Exceptions in Python are a GODSEND. I strongly recommend
to any former C programmer wanting to get rid of a "straightjacket"
to read the following to get an idea how not to write C code in Python
and instead exploit the better side of VHLL:
http://gnosis.cx/TPiP/appendix_a.txt
--
It's a man's life in a Python Programming Association.
More information about the Python-list
mailing list