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

  • Home
  • SEARCH
  • 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 6076425
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T10:36:22+00:00 2026-05-23T10:36:22+00:00

I want to write a function which gets all the variables in a scope,

  • 0

I want to write a function which gets all the variables in a scope, and then determines the
type of each variables.
I am a aware of vars(), dir() and similar, but these functions return a list of strings.
How can I actually get the types ?
I would like to do something like that:

 #this is just pseudo code
 for item in <items in scope>:
     if isinstance(item, someclass):
        del <item which belongs to someclass>

thanks in advance,
Oz

  • 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-23T10:36:23+00:00Added an answer on May 23, 2026 at 10:36 am

    You may be looking for locals, which returns a dict with locals vars name and their values:

    for name, value in locals().items():
         if isinstance(value, someclass):
            do something
    

    OK, I am editing this answer, because it is the closest of what I want:
    I wanted to erase all numpy array. I find it annoying that numpy does not have “clear all” a la octave\matlab, and ipython’s %reset is a bit too much …

    so, here it is:
    In [24]: anp=np.r_[1:10]

     In [25]: np.who()
     Name            Shape            Bytes            Type
     ===========================================================
    
     anp             9                36               int32
    
     Upper bound on total bytes  =       36
    
     In [26]: for name, value in locals().items():
     ....:     if isinstance(value, np.ndarray):
     ....:         print name
     ....:         print value
     ....:         del globals()[name]
     ....: 
     anp
     [1 2 3 4 5 6 7 8 9]
    
     In [27]: np.who()
    
     Upper bound on total bytes  =       0
    

    Thanks for everyone, for the will and the effort!

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

Sidebar

Related Questions

Let's say you want to write a function which gets passed an opaque handle
I want to write a function which can validate a given value (passed as
I want to write a function that accepts a parameter which can be either
i want to write a function that prints multi-dimensional objects which are text (or
I want to write a function like equalp, which gives #t for (equalp Xy
I want to write a function which takes a list of elements l, a
I want to write the following function which should be used in an Excel
I want to write a function in Python that returns different fixed values based
I want to write a function that takes an array of letters as an
I want to write a function that accepts two objects as parameters and compare

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.