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']
print "myVariable"?locals(). Is that sufficient? Note that Python variables are references, so there could be many variables referring to the same single object.locals()solution teases out a dictionary from the current scope, effectively doing the same thing as making your own dictionary, but in a clumsy fashion.