Re: Multi-line string extension

Tim Peters (tim@ksr.com)
Mon, 18 Apr 94 23:49:00 -0400

> > [tim]
> > ...nobody writes "i = 1+2" by hand...

> [larry]
> Though you do see 24*60*60 pretty often.

No argument; "doesn't buy much" isn't "doesn't buy anything".

The saving grace in Python is that typical Python users tend to package
functions in modules more than typical Perl users tend to modularize
functions in packages <wink>, and so in Python you'll _usually_ see
something like

import time
_SECONDS_PER_DAY = 24*60*60 # a module-level binding
_SECONDS_PER_WEEK = _SECONDS_PER_DAY * 7 # ditto

def full_days_in_epoch(): # a function supplied by the module
return int(time.time() / _SECONDS_PER_DAY)

The constant expressions aren't optimized away, but module-level code is
executed only once per job (when the module is first imported), so the
constant expressions here are evaluated only once per job.

It's true that a user might pay a significant price for writing

return int(time.time()/(24*60*60))

today; seems rare in Python, though.

not-to-say-that-all-possible-optimizations-shouldn't-be-done-at-
once<wink>-ly y'rs - tim

Tim Peters tim@ksr.com
not speaking for Kendall Square Research Corp