Create timeit_demo.py
s6 · write_file migrateFix Python 2 print statement to Python 3 function call to avoid SyntaxError.
@@ -8,3 +8,3 @@
import timeit
setup = "from __main__ import my_function"
- print timeit.timeit("my_function()", setup=setup)
+ print(timeit.timeit("my_function()", setup=setup))
Sources
- SyntaxError: invalid syntax - Python Morsels
Indentation issues often result in `IndentationError` exceptions, but sometimes they'll manifest as `SyntaxError` exceptions instead. [...] # SyntaxError: invalid syntax
- Invalid Syntax in Python: Common Reasons for SyntaxError – Real Python
There are a few elements of a `SyntaxError` traceback that can help you determine where the invalid syntax is in your code:
- How to Fix 'SyntaxError: invalid syntax' in Python
"SyntaxError: invalid syntax" is one of the most common errors Python developers encounter. It means Python cannot parse your code because it violates the language's grammar rules. The tricky part is that the error location Python reports is not always where the actual mistake is.