printing all variables

S

Sheldon

Good day,

I would like to know if there is a way to print all the variables set
in a python program with having to write
"print variable" on all?

sincerely,
Sheldon
 
D

Duncan Booth

Sheldon said:
Good day,

I would like to know if there is a way to print all the variables set
in a python program with having to write
"print variable" on all?
Not all the variables in a program (that would be rather more than you
want), but you can print all the variables in a specific namespace easily
enough:
pprint(locals())

{'__builtins__': <module '__builtin__' (built-in)>,
'__doc__': None,
'__name__': '__main__',
classvar = []
def __init__(self, n):
self.n = n

{'__doc__': None,
'__init__': <function __init__ at 0x00B4A070>,
'__module__': '__main__',
'classvar': []}
 
S

Sheldon

Duncan Booth skrev:
Sheldon said:
Good day,

I would like to know if there is a way to print all the variables set
in a python program with having to write
"print variable" on all?
Not all the variables in a program (that would be rather more than you
want), but you can print all the variables in a specific namespace easily
enough:
pprint(locals())
{'__builtins__': <module '__builtin__' (built-in)>,
'__doc__': None,
'__name__': '__main__',
classvar = []
def __init__(self, n):
self.n = n

{'__doc__': None,
'__init__': <function __init__ at 0x00B4A070>,
'__module__': '__main__',
'classvar': []}

Thanks Duncan! This really helps!

/Sheldon
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top