If you are very new to Python Programming and trying to run your .py file in the command line (or terminal) and you see the error "SyntaxError: '(' was never closed", well then you have look at the error text and grab more details from it.
How to know which line has the issue?
When you run your Python code and it generates an error you can a traceback printed out in the console which contains the details of the error.
Let's understand this with a simple example.
example.py
print("Hello World"
When I run this example.py file in the terminal I get the below traceback
1. % python3 example.py
2. File "/Users/c2ctech/Desktop/example.py", line 1
3. print("Hello, World!"
4. ^
5. SyntaxError: '(' was never closed
There are a few important things to note here, at line number 2, you will see which file had an error and at what line. Note, we are getting this error on line 1.
Line number 3 highlights exactly at what statement the error is and line 5 tells us that it is a SyntaxError.
So you read the error as "There is a SyntaxError on line 1 of my example.py file"
How to fix this error
The fix is self-explanatory, but one could be very new to programming, so let me elaborate, every programming language has a syntax, a structure that you should follow, if it is not followed correctly, you get errors when you run your code.
The print function in Python needs to be enclosed within parenthesis, If you miss the closing braces, you will get this error we are dealing with here.
The fix is simple, make sure to close the print function with a closing parenthesis.
print("Hello World")
Facing issues? Have Questions? Post them here! I am happy to answer!
Rakesh (He/Him) has over 14+ years of experience in Web and Application development. He is the author of insightful How-To articles for Code2care.
Follow him on: X
You can also reach out to him via e-mail: rakesh@code2care.org
- Get the current timestamp in Java
- Java Stream with Multiple Filters Example
- Java SE JDBC with Prepared Statement Parameterized Select Example
- Fix: UnsupportedClassVersionError: Unsupported major.minor version 63.0
- [Fix] Java Exception with Lambda - Cannot invoke because object is null
- 7 deadly java.lang.OutOfMemoryError in Java Programming
- How to Calculate the SHA Hash Value of a File in Java
- Java JDBC Connection with Database using SSL (https) URL
- How to Add/Subtract Days to the Current Date in Java
- Create Nested Directories using Java Code
- Spring Boot: JDBCTemplate BatchUpdate Update Query Example
- What is CA FE BA BE 00 00 00 3D in Java Class Bytecode
- Save Java Object as JSON file using Jackson Library
- Adding Custom ASCII Text Banner in Spring Boot Application
- [Fix] Java: Type argument cannot be of primitive type generics
- List of New Features in Java 11 (JEPs)
- Java: How to Add two Maps with example
- Java JDBC Transition Management using PreparedStatement Examples
- Understanding and Handling NullPointerException in Java: Tips and Tricks for Effective Debugging
- Steps of working with Stored Procedures using JDBCTemplate Spring Boot
- Java 8 java.util.Function and BiFunction Examples
- The Motivation Behind Generics in Java Programming
- Get Current Local Date and Time using Java 8 DateTime API
- Java: Convert Char to ASCII
- Deep Dive: Why avoid java.util.Date and Calendar Classes
- Java: Check if a String contains another Sub-String with Examples - Java
- How to Create a Website (Webpage) using HTML on Windows Notepad - Windows
- Upload a File in Microsoft SharePoint using PowerShell Script - SharePoint
- How to add multiple spaces between html page text - Html
- [macOS] NetBeans IDE cannot be installed. Java (JRE) found on your computer but JDK XX or newer is required. - MacOS
- How to save a file in Nano Editor and Exit - Linux
- Facebook : Warning: Request without access token missing application ID or client token - Facebook
- Fix: ModuleNotFoundError: No module named requests - Python