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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T01:59:26+00:00 2026-05-22T01:59:26+00:00

Given the python function: def MyPythonMethod(value1, value2): # defining some variables a = 4

  • 0

Given the python function:

def MyPythonMethod(value1, value2):
    # defining some variables 
    a = 4
    myValue = 15.65
    listValues = [4, 67, 83, -23]

    # doing some operation on the list
    listValues[0] = listValues[1]       

    # looping through the values
    for i in listValues:
        print i 

How can I extract the names and types of all the variables in method MyPythonMethod?

Ideally, I’d like to get all variable names and their types given a method name. for example, the output for method MyPythonMethod will look like this:

varNames = ["a", "myValue", "listValues", "i"]

varTypes = ["int", "float", "list", "float"]

Any ideas?

  • 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-22T01:59:27+00:00Added an answer on May 22, 2026 at 1:59 am

    1 Variables don’t have a type in python. Objects have a type, and variables point to objects.

    [2] you can use the inspect module to get info about the internals of your function.
    Read the docs — they will tell you what is available for inspection.
    MyPythonMethod.func_code.co_varnames will give you the local variable names, for example.
    ( And note that MyPythonMethod, as defined, is actually a function, not a method. )

    [3] But even when you get the names of the local variables, the aren’t bound to any objects
    except while the function is executing. The value 4 is bound to local var ‘a’ in the function — before and after the function is called, there is no ‘a’ and it’s not bound to anything.

    [4] If you run the function in the debugger, you can halt the execution at any point and inspect the variables and objects created in the function.

    [5] If the function raises an exception, you can catch the exception and get access to some of the state of the function at the time of the exception.

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

Sidebar

Related Questions

Given the python code: import sys import os def MyPythonMethod(value1, value2): # defining some
Given an instance of some class in Python, it would be useful to be
Given a function: def func(f1, kw='default'): pass bare_argspec = inspect.getargspec(func) @decorator def func2(f1, kw='default'):
Python has a built in function sum , which is effectively equivalent to: def
Here's a simple python function that checks if a given url is valid: from
I have been doing some work with python-couchdb and desktopcouch. In one of the
How do I learn where the source file for a given Python module is
Given a Python object of any kind, is there an easy way to get
I was given this Python code that would calculate an MD5 value for any
How do I load a Python module given its full path? Note that the

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.