Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Python
Help me abstract this (and stop me from using eval)
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Daniel Klein, post: 5053333"] Hi! I've got import scripts for a bunch of csv files into an sqlite database. Ihave one csv file per language. I don't write directly to the sqlite db; this is a django app and I'm creating items in my django models. My script (scripts, unfortunately) work just fine, but it feels beyond stupid to have one script per language--importgerman, importfrench etc. The problem is that I don't know how to abstract which language I'm currently writing to. Here's the central loop: [URL]http://pastebin.com/NBT6feNB[/URL] This is for the Polish version of the script, of course, the one that gets fed pl.csv. For those unfamiliar with django, I need to first retrieve the message instance for issue name / long text / short text / category name. Hence the ugly tempmes stuff. So ideally I would tell the script which language I'm currently importing and based on that it would write to the appropriate text fields. But I don'tknow how to abstract this: tempmes.polish = row[1] Well, I do. Like this: eval("tempmes." + language + " = row[1]") But... eval is evil, no? There's got to be a better way? [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Python
Help me abstract this (and stop me from using eval)
Top