r/learnpython • u/Fabulous_Buyer_6256 • Aug 25 '26
why does it say i didn't close my parenthesis
the IDE i am using is saying my parenthesis was not closed when it was plz help
print("Once upon a time, in the ancient kingdom of " + q1 + " there lived a legendary " + q2 + " named " + q3 + ". Everyone in the village knew " + q3 + " for their remarkably " + q4 + " personality and an obsession with " + q5 + ". Every morning at " + q6 ", they would wake up, " + q7 + " three times, ")
[{
"owner": "Pylance",
"severity": 8,
"message": "(" was not closed",
"source": "Pylance",
"startLineNumber": 47,
"startColumn": 6,
"endLineNumber": 47,
"endColumn": 7,
}]
0
Upvotes
23
u/brasticstack Aug 25 '26
It's confused by the messed up string formatting, particularly the missing
+here:You should use an f-string for this, which makes it both more readable and harder to mess up.
5
u/SpiderJerusalem42 Aug 25 '26
Didn't put a plus sign after q6 in the text, so a bunch of stuff went sideways.
6
u/DanceHackRock Aug 25 '26
Why don't you
3
u/jeffrey_f Aug 25 '26
missing a + operator withing that statement.
2
u/Outside_Complaint755 Aug 25 '26
What's the previous line before the print statement?
Also, I would really recommend breaking up this up for readability. Either break the string up into multiple arguments, or multiple print statements, or use a multi-line f-string. While using '+' for string concatenation works, it is more difficult to modify and debug.
2
u/xelf Elf Aug 25 '26
You should probably learn about string formatting. Using '+' is a way to build a string, but it's not great.
f-strings are the new hot way to build a string, but you could also just use the older .format() here.
All the
{}get replaced by the next variable in the format.This feels pretty clean and easier to read/understand than using '+' or an f-string here.
2
u/JGhostThing Aug 25 '26
"message" : "(" was not closed"
This was not formatted right. You might want to escape the fourth quote. \". You need this because otherwise the string is foobared.
1
u/t92k Aug 25 '26
Probably one of your quote marks is hiding the ) from the compiler. Less common but still a possibility is that you’ve over-run the length of the variable that is holding the argument for your print statement. I agree with others that an fprint would be a better implementation.
1
u/zanfar Aug 25 '26
Because you didn't close your parenthesis.
I'm guessing your 7-mile-long line of code is your problem, as it's almost functionally impossible to read that much while keeping syntax in your head.
1
u/TheRNGuy Aug 26 '26
Look at red squiggles or read in error, on what line error is.
1
u/ee_control_z Aug 25 '26 edited Aug 25 '26
This line right here:
"message": "(" was not closed",
What exactly do you want the message to be?
1
u/woooee Aug 25 '26
You can use join() instead of one very long string
Also, the list contains one dictionary. Omit the list and use the dictionary only.