Just need to pick the right once from the dict that locals()
gives you.
>>> a = 2
>>> b = 3
>>>
>>> print(locals())
{'__doc__': None, 'b': 3, 'a': 2, '__spec__': None,
'__builtins__': <module 'builtins' (built-in)>, '__name__': '__main__',
'__loader__': <class '_frozen_importlib.BuiltinImporter'>, '__package__': None}
Probably better to put the variables you want to print into their own dict and then print the dict keys
>>> myvars = {'a': 2, 'b': 3}
>>> print(', '.join(myvars))
a, b
Or, with locals()
again
>>> a = 2
>>> b = 3
>>>
>>> print([x for x in locals() if not x.startswith('_')])
['b', 'a']