Basic Python question: referencing original variable inside for loop? -
Quick, novice Python Scroping question. How can I ensure that the original variable changes in the loop given below? > To print convertible print, not original. There is no sign of dragon, okay? Thank you! print
References Python pointers (conceptual level) instead and objects.
What you want to do is assign the new value of the name to some name that exists after the loop.
Loop Open and use each name where you need it, like
name_level_1_translated = util.translate ( "iw", "en", name_level_1.encode ( 'utf-8')) print name_level_1_translated Name_level_2_translated = use.translate ( "iw", "en", name_level_2.encode ( 'utf-8')) do_stuff (name_level_2_translated)
or If you are going to use each of the same names, just create a list and use that place.
names = [name_level_1, name_level_2, to name name_level_3, name_level_4] translated_names = [util.translate ( "iw", "en", Name_encode ( 'utf-8')) names In translated_names: print name
You can access them index:
print name [0]
Comments
Post a Comment