K
K
kolomiec_artiom2018-10-02 01:12:39
Python
kolomiec_artiom, 2018-10-02 01:12:39

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

2 answer(s)
D
DDDsa, 2018-10-02
@DDDsa

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}
>>>

P
Puma Thailand, 2018-10-02
@opium

Print variable?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question