Hi everyone,

I am a newbie and I must be overlooking a simple thing here. But how
do I typecast a string to the type needed by a mapped class, which is
identified at run time?

I have a class,

class Record(object):
    pass

which I map to one of different tables identified at run time. I get
strings like this

col, val = raw_input(), raw_input()

(my actual application uses HTML form, but this was for testing) which
I try to use to insert a new record, like:

rec = Record()
setattr(rec, col, val)

This works if col is a string (the column subclassing SQLAlchemy's
String) but not otherwise. I can identify the type of the column as

coltype = rec.c[col].type

I probably can write a big if elif else to identify the type and do
the typecasting. e.g.:

if isinstance(coltype, Integer):
    val = int(val)

but is there a canonical solution already there?

Regards,

Muhammad


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalchemy@googlegroups.com
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