Oleg kindly provided the solution below for generating SQLObject
classes from a list of pre-existing table names.
def makeTable(name):
class Test(SQLObject):
class sqlmeta:
table = name
def __classinit__(cls, new_attrs):
cls.__name__ = name
SQLObject.__classinit__(cls, new_attrs)
return Test
test1 = makeTable("test1")
test2 = makeTable("test2")
This works wonderfully, but I get collisions in the registry, if I run:
test1 = makeTable("test1")
<intervening code>
testOther = makeTable("test1")
I'd like to solve this generally. I can postpone the problem by using
sqlmeta.registry, but there's some chance that test1 will be created
twice in the same namespace anyway.
I can search the namespace before creating 'test1', and if I find
'test1', either use it (and assume that it is what I think it is -
feh) or generate a new name (e.g. 'test1_0', 'test1_1' and so
forth). Doable but not as elegant as I'd like.
In principle, anonymous classes would be ideal, e.g.
self.file = type("", (object,), {'close':lambda slf: None})()
from: http://www.thescripts.com/forum/thread20941.html
So I'm writing to ask whether there are any hooks or prior models I
could work from.
Thanks.
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
sqlobject-discuss mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/sqlobject-discuss