Quick, newbie Python scoping question. How can I make sure that the original variables get changed in the for-loop below?
for name in [name_level_1, name_level_2, name_level_3, name_level_4]:
name = util.translate("iw", "en", name.encode('utf-8'))
print name_level_1
In other words, I want the print statement to print out the changed variable, not the original. Python doesn’t have pointers, right?
Thanks!
Python has references and objects instead of pointers (from a conceptual level).
What you want to do is assign the new value of name_level_1 to some name that exists after the loop.
So, either unwrap the loop and use each name where you need it, e.g.
or, if you’re going to use each name the same way, just create a list and use that everywhere.
You can also access them by index: