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 8066681
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:05:00+00:00 2026-06-05T12:05:00+00:00

There’re two scripts: #imptee.py foo = "abc" def show(): print "foo from imptee:",foo #impter.py:

  • 0

There’re two scripts:

#imptee.py
foo = "abc"

def show():
    print "foo from imptee:",foo

#impter.py:

#!/usr/bin/env python

from imptee import *

show()

foo = 123
 
print "foo from impter:",foo
show()

When I run impter.py, it yields the following result:

foo from imptee: abc

foo from impter: 123

foo from imptee: abc

I just don’t understand why after assigning 123 to variable foo, show() still print ‘abc’, not 123. I think after "from imptee import *", foo and show() are in global namespace now, and there are no local namespace. I do understand that the searching sequence should be: local namespace, global namespace, bulit-ins namespece. So, why is that? Could someone give me a hand, please?
THX!

  • 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-06-05T12:05:01+00:00Added an answer on June 5, 2026 at 12:05 pm

    Modules have separate namespaces. When you import from one module to another, you are importing the values (usually functions but in this case a literal “abc”) from the source module and assigning them to names in the destination module.

    When you do from imptee import *, you are assigning them to the same name that they had in the source module, but that doesn’t actually change the pointers in the source module. It just duplicates the names.

    When you change the assignment in the destination module after the import, that doesn’t change anything in the source module, because even though the names look the same they are separate pointers and can point to separate things.

    This might be more clear if you did import imptee and then manually assigned the value: foo = imptee.foo. Then later you’ll do foo = 123, and it makes sense that the value of foo in the destination module has changed but the value of the similarly-named pointer in the source module has not.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

There are two ways that I know that you can fetch results in Rails
There are 3 different ways to get data out of a BLOB column from
There are two tables: aspnet_users and aspnet_membership. Can anyone elaborate on the reasons why
There are two major fix engines: opensource QuickFix http://www.quickfixengine.org/ commercial Fix Antenna http://www.b2bits.com/trading_solutions/fix_engines/fix_engine_cpp.html What
There are many tutorials that talk about deleting index.php from the url. But I
There is a constant I'm using from the iOS SDK. I printed out the
There are two weird operators in C#: the true operator the false operator If
There are two popular closure styles in javascript. The first I call anonymous constructor
There is a similar question from 2009 which mentions Wufoo and FormAssembly services. Are
There are two ways to get a NSManagedObjectContext that I know of: create a

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.