Answer the question
In order to leave comments, you need to log in
How to see the value of variables when a program is running in Python?
Goodnight!
My program is on a pythonanywhere server (not for the sake of publicity, but because of possible hot combinations that I missed). After it works for a while, it stops working. In this case, there are no errors. Most likely, a crooked value is assigned to some variable.
How can you find out the value of all variables at the moment?
Answer the question
In order to leave comments, you need to log in
globals()
and locals()
for help:
>>> a = 123
>>> b = 'asd'
>>> def test():
... c = True
... d = 55.36
... print('GLOBALS:')
... pprint(globals())
... print('LOCALS:')
... pprint(locals())
...
>>> from pprint import pprint
>>> test()
GLOBALS:
{'__annotations__': {},
'__builtins__': <module 'builtins' (built-in)>,
'__doc__': None,
'__loader__': <class '_frozen_importlib.BuiltinImporter'>,
'__name__': '__main__',
'__package__': None,
'__spec__': None,
'a': 123,
'b': 'asd',
'pprint': <function pprint at 0x103ce9158>,
'test': <function test at 0x101d62e18>}
LOCALS:
{'c': True, 'd': 55.36}
>>>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question