detect interactivity
Dave Angel
davea at ieee.org
Wed Dec 30 01:28:32 EST 2009
Steve Holden wrote:
> Roald de Vries wrote:
>
>> On Dec 30, 2009, at 2:28 AM, Dave Angel wrote:
>>
>>
>>> Roald de Vries wrote:
>>>
>>> <snip>
>>> mehow define a different set of functions???
>>>
>> I'm using a database, and want to use python interactively to manipulate
>> it. On the other hand, I also want to be able to use it
>> non-interactively. In that case, it would be a waste of CPU to load the
>> function/class definitions meant for interactive use.
>>
>>
> This is an extreme case of premature optimization. Write the code and
> run it. Do you have any idea how much extra time and memory loading the
> additional code will require? If not, it's a waste of your time to even
> think about omitting the stuff required for interactive use.
>
> Once you get a handle on the structures and functions required for
> interactive vs. non-interactive use you can consider refactoring the
> code so that the non-interactive programs don't need to import the stuff
> that's exclusively for interactive use. But frankly I wouldn't waste
> your time.
>
> regards
> Steve
>
Ron:
You'd be surprised how little additional space and time a few functions
take up.
But in any case, if (after measurement) you decide you really want them
to be optional, then just have a different module that the interactive
users import than the one that you run in production. Have both modules
import the bulk of the code, and keep the differences in one place.
It's also possible to build stubs for the missing functions, and import
them and overwrite the stubs, upon first reference. I've done that sort
of thing in other language environments, when it made a definite
measurable difference (like say 50%)
DaveA
More information about the Python-list
mailing list