On Jul 25, 2012, at 6:49 PM, Stephan Hügel wrote:

> 
> if you want to make a new class that has a new name from the start, use 
> type():
> 
> def __init__(self, reference):
>     self.reference = reference
> 
> d = dict(
>       __tablename__ = listname.lower()
> 
>       id = db.Column("id", db.Integer(), primary_key=True)
>       reference = db.Column(db.String(50), nullable=False, unique=True)
> 
>       __init__ = __init__
> )
> my_class = type(listname, (db.Model,), d)
> 
> 
> 
> Doing this creates classes (e.g. <class 'flask_sqlalchemy.lak'>) , but is 
> there some way for me to instantiate them without resorting to some eval 
> magic in my for loop?

instantiate, as in, instance of the new class?  "my_class" above is a regular 
Python class,  just instantiate - myclass(x, y, z).   


> What I'd like to end up with is programmatically created instances 
> (myapp.models.lak) that I can use the same way as my "normally" instantiated 
> classes.

that's what type() gives you.  Its the exact same thing as using "class Foo()".

-- 
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.

Reply via email to