将变量传递给另一个变量

时间:2012-07-19 20:26:36

标签: django

  

可能重复:
  Dynamically set local variable in Python

我试图执行此操作:

        # the request send a number and its ok, the variable have good informations.
        test = request.POST[member.user.username]

        # SyntaxError at ***here***, can't assign to operator
        group%d % test = member.user.username

我也试过了:

        test = request.POST[member.user.username]
        group%d = member.user.username % test

并且:

        test = request.POST[member.user.username]
        group%d = member.user.username % (test)

对语法有什么想法?

1 个答案:

答案 0 :(得分:0)

您可以使用字典来执行此操作:

test = request.POST[member.user.username]
d={}
d['group'+str(test)]= member.user.username

也许,有更好的方法,但我只知道这一个。