One case which is prevalent in duplicates is the requirement to use quotes for external processes. A workaround for that is to not use a shell, which removes the requirement for one level of quoting.
(which also fixes the bug that shell metacharacters in filename would need to be escaped from the shell, which the original code failed to do; but without a shell, no need for that).
Of course, in the vast majority of cases, you don't want or need an external process at all.
with open(filename) as fh:
for line in fh:
if 'foo' in line:
print("bar")
When you have several words like this which you want to concatenate in a string, I recommend using format or f-strings which increase readability dramatically (in my opinion).
To give an example:
s = "a word that needs quotation marks"
s2 = "another word"
Now you can do
print('"{}" and "{}"'.format(s, s2))
which will print
"a word that needs quotation marks" and "another word"
>>> print('{!r}'.format('a word that needs quotation marks'))
'a word that needs quotation marks'
The flag !r is a shorthand of the repr() built-in function1. It is used to print the object representation object.__repr__() instead of object.__str__().
In case you don't want to use escape characters and actually want to print quote without saying " or \" and so on, you can tell python to print the ASCII value of the " character.
The quote character in ASCII is 34, (single quote is 39)