2

This one works (one line only):

 c.execute(f"SELECT Firm, Platform, `Sale in million` FROM database WHERE Platform IN ({','.join('?' for _ in list_table)}) ORDER BY Firm", (list_table))

But these ones don't (2 lines):

c.execute(f"SELECT Firm, Platform, `Sale in million` FROM database 
 WHERE Platform IN ({','.join('?' for _ in list_table)}) ORDER BY Firm", (list_table))
c.execute(f"SELECT Firm, Platform, `Sale in million` FROM database" 
 f"WHERE Platform IN ({','.join('?' for _ in list_table)}) ORDER BY Firm", (list_table))"
c.execute("SELECT Firm, Platform, `Sale in million` FROM database" 
 f"WHERE Platform IN ({','.join('?' for _ in list_table)}) ORDER BY Firm", (list_table))"

How do you use f-string in multiple lines?

Granny Aching
1,4352 gold badges16 silver badges38 bronze badges
asked Jan 9, 2019 at 18:59
1

1 Answer 1

1

The issue stems from essentially invalid multi lines and not really any fault of f-string.. Note that you only need to use your variables inside the {} parenthesis and not pass them separately with f-string syntax. Use triple quotes or backslashes at end of strings to use multi line strings. Link to docs

test = "this is a 
 bad multiline " #Raises SyntaxError: EOL while scanning string literal
test = ''' this is a 
 valid multiline'''
a = "answer"
print(f'''test
 is complete. check {a} ''')
answered Jan 9, 2019 at 19:08
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.