Help me abstract this (and stop me from using eval)

Steven D'Aprano steve+comp.lang.python at pearwood.info
Wed Oct 3 12:36:09 EDT 2012


On Wed, 03 Oct 2012 09:23:03 -0700, Daniel Klein wrote:

> 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't know how to abstract this:
> 
> tempmes.polish = row[1]
> 
> Well, I do. Like this:
> 
> eval("tempmes." + language + " = row[1]")

setattr(tempmes, language, row[1])



-- 
Steven



More information about the Python-list mailing list