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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T13:42:08+00:00 2026-06-06T13:42:08+00:00

my_var = 3 assert(‘my_var’ in locals()) import a_module assert(‘a_module’ in locals()) from sys import

  • 0
my_var = 3
assert('my_var' in locals())

import a_module
assert('a_module' in locals())

from sys import *
assert('stdin' in locals())

I also think you can inject with calls to locals() and globals()?

Anyway, I love python because it’s so explicit with imports. If a name is used, you can usually trace back to exactly where that name was defined. But, I’ve recently been running into modules wherein I want to find where the name qux is defined. The module itself contains no from something import *, no locals or globals, but when I CTRL+F for that name I find it only on the RHS of expressions, nowhere defined!

So my question is this: what are all the mechanisms by which a name can enter the local namespace? Can normal imports inject into my local namespace?

  • 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-06T13:42:09+00:00Added an answer on June 6, 2026 at 1:42 pm

    Some other module may inject the name in this module:

    #x.py
    import y
    y.lol = 1
    y.func()
    

    And this module does not define it:

    #y.py
    def func():
        print(lol)
    

    Another crazy way someone may inject code in another module would be:

    #a.py
    import sys
    sys._getframe(1).f_globals['lol'] = 1
    

    So, a.py will inject the name lol in whoever import it

    #b.py
    import a
    print(lol)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Rather than doing my_var = my_var+'extra string'; is there a shorthand method like .=
I have a file called 34.php?session=2534464a39a2c97cb7113689726a4e52 in my /var/www/html folder but I can't view
I have the following linq expression pulling all data from my database: var items
I have just updated my version of NewtonSoft JSON.NET from version 3.0.0 to 3.5.0
I'm getting this error on my production environnent: (from prod.log) [2012-01-30 17:00:51] request.CRITICAL: Doctrine\ORM\Mapping\MappingException:
This test is to check that I can return a ViewModel object by creating
my controller can return different views depending on action method logic. Action method 'Create'
I'm trying to create an assert method in Javascript. I've been struggling with arguments.callee.caller
I'm rolling my own ActivatableCollection<T> for db4o but cribbing heavily from the builtin ActivatableList<T>
Using the new Rhino Mocks 3.5 Arrange/Act/Assert (AAA) Testing style, I'm having problems writing

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.