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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T05:13:43+00:00 2026-06-02T05:13:43+00:00

locals() is a dict. If I do a simple: for i in locals().keys(): type(i)

  • 0

locals() is a dict. If I do a simple:

for i in locals().keys():
     type(i)

…what’s returned is that the names are all strings (yes, in point of fact, they are) but those keys indicate different types – one might be, say, a module. Some reference types (objects) but also primitive types (e.g. int, string).

In some sense, I want to extract the name from the string. Looked at how to do this with the attributes on a string but no go. I believe I need something from introspection, but what?

  • 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-02T05:13:46+00:00Added an answer on June 2, 2026 at 5:13 am

    locals().keys() returns all the variable names bound in local space. Since they are names, they are all strings. (In Python 2.x you could use locals().iterkeys() for this also, to get an iterator.)

    Try locals().values() instead. For Python 2.x, you can use locals().itervalues() to get an iterator.

    Or locals().items() to get key, value pairs. For Python 2.x you can use locals().iteritems() to get an iterator.

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

Sidebar

Related Questions

What i have: Several references to the same partial but with different locals like
I know it's not Pythonic to write functions that care about the type of
my_var = 3 assert('my_var' in locals()) import a_module assert('a_module' in locals()) from sys import
has anyone an idea why I have the following problem with passing locals to
I'm aware of using globals(), locals() and getattr to referance things in Python by
Usually using Visual Studio's debugger is a breeze. Scanning through Locals quickly shows the
Can I define a function which, when called, inserts new locals into the caller's
Using local variables seems advisable in a partial that could be used application-wide to
So I created the following file (testlib.py) to automatically load all doctests (throughout my
I want to have a function in a different module, that when called, has

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.