Namespaces/introspection: collecting sql strings for validation
Peter Otten
__peter__ at web.de
Mon Apr 23 02:07:14 EDT 2007
Martin Drautzburg wrote:
> > def SQL(sql, checked=set()):
> > if sql in checked:
> > return True
> > if not valid_sql(sql): raise ValueError
> > checked.add(sql)
> > return sql
>
> No this does not do the trick. I will not be able to validate an sql
> statement bofore I run over the piece of code that uses it. Or I would
> have to define all my sql = SQL stuff on module level, isn't id. I
> mean, the problem is: when are those sql = SQL statement really
> ececuted?
Let's see:
>>> def SQL(sql):
... print sql
...
>>> a = SQL("module")
module # that one was obvious
>>> class A:
... b = SQL("class")
... def method(self, c=SQL("default arg")):
... d = SQL("method")
...
class # ha, class statements are executed, too...
default arg # ...as are default arguments
Peter
More information about the Python-list
mailing list