Late binding and late execution (was: Beautiful Python)

Cameron Laird claird at lairds.us
Wed Dec 28 12:08:03 EST 2005


In article <0g44r1p8ds42u7svmktvtogouq02lqei30 at 4ax.com>,
Dennis Lee Bieber  <wlfraed at ix.netcom.com> wrote:
>On Tue, 27 Dec 2005 21:35:46 -0600, news at absamail.co.za declaimed the
>following in comp.lang.python:
>
>> Wow ?!   I've only started looking at python but that sounds like very
>> dangerous programming !  Can you give an example.
>>
>	Even a simple "def" statement is an executed statement in Python.
>
>	There is no difference, in Python, between an imported file and a
>file invoked directly on the command line -- other than the "name" given
>the module. Many files take advantage of that to supply a stand-alone
>mode by putting something like:
>
>if __name__ == "__main__":
>	# do something as a stand-alone module
>	# likely by setting up some parameters from the command line
>	# and invoking the real work function/class
>	# for example:
>	term1 = sys.argv[1]
>	optionals = sys.argf[2:]
>	myWorkRoutine(term1, optionals)
>
>---
>
>	If imported (call it module "impy"), one could then do things like
>
>import impy
>
>...	# other stuff
>impy.myWorkRoutine(stuff, nonsense)
			.
			.
			.
Along with all the other true things that have been written in this
thread, I wonder whether some participants realize how often real-world
code needs some sort of "conditional source"--for example, if we're in
a context where a particular database manager is locally-licensed, then
we need to import and use a particular set of definitions, otherwise we
fall back to network access of ...  Contingent "declarations", such as
"global" or "import", might seem to be mere optimizations, but they're
important ones for the kinds of problems I encounter that need to do
real work.



More information about the Python-list mailing list