How to get all variable and method names used in script

前端 未结 4 1076
攒了一身酷
攒了一身酷 2020-12-25 08:54

It can be weird but I am looking for a way to get automatically all variables and method within a python script.

For example,

a = 1
b = 2
c = 3
myLis         


        
4条回答
  •  南笙
    南笙 (楼主)
    2020-12-25 09:26

    You can use dir() built-in for this. Suppose you save your file as test.py. You can do as follows:

    >>> import test
    
    >>> dir(test)
    ['__builtins__', '__doc__', '__file__', '__name__', '__package__', 'a', 'b', 'c', 'f', 'myList', 'someMethod']
    >>> 
    

提交回复
热议问题