Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 991765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T06:09:39+00:00 2026-05-16T06:09:39+00:00

Quick, newbie Python scoping question. How can I make sure that the original variables

  • 0

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!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-16T06:09:39+00:00Added an answer on May 16, 2026 at 6:09 am

    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.

    name_level_1_translated = util.translate("iw", "en", name_level_1.encode('utf-8'))
    print name_level_1_translated
    
    name_level_2_translated = util.translate("iw", "en", name_level_2.encode('utf-8'))
    do_stuff(name_level_2_translated)
    

    or, if you’re going to use each name the same way, just create a list and use that everywhere.

    names = [name_level_1, name_level_2, name_level_3, name_level_4]
    translated_names = [util.translate("iw", "en", name.encode('utf-8')) for name in names]
    for name in translated_names:
        print name
    

    You can also access them by index:

    print names[0]
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a quick newbie question here. I have a method that calculates a value
Quick question that I can't seem to find an answer for. If I am
quick and very basic newbie question. If i have list of dictionaries looking like
quick question on GWT from a newbie. Considering the following code: FlowPanel block =
I am newbie to .Net and I got a quick question. In my web
Quick newbie question here, how do I access totalResults ? XML <?xml version=1.0 encoding=UTF-8?>
Quick newbie question. Let's say I have the following code in Vim: void main()
Quick question about OpenMP: I'm not sure how to implement a nested double for
C++ newbie here with a quick question. How do I print the contents of
I'm sorry for this newbie question, but I need a quick answer to tell

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.