Are circular dependencies possible in Python?

John Machin sjmachin at lexicon.net
Sun Apr 10 00:41:45 EDT 2005


On Sat, 9 Apr 2005 15:57:15 GMT, Tim Tyler <tim at tt1lock.org>  wrote:

>Like C, Python seems to insist I declare functions before calling
>them

One is left wondering what gave you that impression about Python.
Nothing could be further from the truth. The only construct in Python
that smells anything like a declaration is the wartish "global". The
Python philosophy is that everything is dynamic. You don't muck about
with declarations; you just get on with the job. See example below,
where we have a list of functions, which of course all follow the same
protocol, but what that protocol is is of no concern of the Python
compiler.

def nothing_to_declare(data_fields, validation_funcs, other_info):
    for k, fld in enumerate(data_fields):
	validation_funcs[k](fld, k, other_info)

Aside: How many iterations would it take for the average C programmer
to get the declaration for "validation_funcs" correct?

Others have pointed out that "def" is executed. So is "class". An OO
example of dynamism would be a bit longer, but would involve creating
classes on the fly and stuffing into them whatever methods are
required for the task at hand.

HTH,

John




More information about the Python-list mailing list