Someone has recently demonstrated to me that we can print variables in Python like how Perl does.
Instead of:
print("%s, %s, %s" % (foo, bar, baz))
we could do:
print("%(foo)s, %(bar)s, %(baz)s" % locals())
Is there a less hacky looking way of printing variables in Python like we do in Perl? I think the 2nd solution actually looks really good and makes code a lot more readable, but the locals() hanging around there makes it look like such a convoluted way of doing it.
The only other way would be to use the Python 2.6+/3.x
.format()method for string formatting:Or referencing specific variables by name: