Fix Python – String formatting: % vs. .format vs. f-string literal

There are various string formatting methods:

Python <2.6: "Hello %s" % name Python 2.6+: "Hello {}".format(name)   (uses str.format) Python 3.6+: f"{name}"   (uses f-strings) Which is better, and for what situations? The following methods have the same outcome, so what is the difference? name = "Alice" "Hello %s" % name "Hello {0}".format(nam....

Fix Python – Installing specific package version with pip

I am trying to install version 1.2.2 of MySQL_python, using a fresh virtualenv created with the –no-site-packages option. The current version shown in PyPi is 1.2.3. Is there a way to install the older version? I have tried:
pip install MySQL_python==1.2.2

However, when installed, it still shows MySQL_python-1.2.3-py2.6.egg-info in the site pack….

Fix Python – How do I split the definition of a long string over multiple lines?

I have a very long query. I would like to split it in several lines in Python. A way to do it in JavaScript would be using several sentences and joining them with a + operator (I know, maybe it’s not the most efficient way to do it, but I’m not really concerned about performance in this stage, just code readability). Example:
var long_string = ‘so….