I've seen this question but I think I have more nested quotes and it's doing my head in.
How would I convert the following line into an f-string?
file.write('python -c "{code}"'.format(code="open('test.txt', 'w');"))
I've seen this question but I think I have more nested quotes and it's doing my head in.
How would I convert the following line into an f-string?
file.write('python -c "{code}"'.format(code="open('test.txt', 'w');"))
There's barely anything to do here:
code="open('test.txt', 'w');"
file.write(f'python -c "{code}"')
You can of course also put the value of the variable in the f-string, but that would be silly:
file.write(f'python -c "{"open(\'test.txt\', \'w\');"}"')
Because replacing a string with a string is just, you know, inserting a string, no string formatting needed
file.write('python -c "open(\'test.txt\', \'w\');"')