On 2012-08-12, at 16:15 , rafiee.nima wrote: > Hi I need to to assign dynamic name to a variable I use blow code : > for item,value in request.POST.items(): > if item=="kid_room" > vars()[item]="ok" > list.append({"a":kid_room}) > data=simplejson.dumps(list,cls=DjangoJSONEncoder) > return HttpResponse(data, mimetype="application/json") > > which kid_room is request.POST item > but i got error that kid_room is not defined which means vars()[item]="ok" > dose not work > please help
Why the hell would you want to do something like that in the fist place? How about jus writing: if item == 'kid_room': list.append({'a': 'ok'}) ? If the name is hardcoded there obviously is no need to dynamically assign it, and if it's not you can just use a dict. I see no reason to even try to do that, and so far I've never seen one when coding. -- You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com. To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/django-users?hl=en.