Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I check the syntax of Python script without executing it?

I used to use perl -c programfile to check the syntax of a Perl program and then exit without executing it. Is there an equivalent way to do this for a Python script?

like image 363
Eugene Yarmash Avatar asked Nov 26 '10 10:11

Eugene Yarmash


People also ask

How do you check Python syntax errors?

Python code checker tool Python error checker tool allows to find syntax errors (lint). You can test your Python code online directly in your browser. If a syntax error is detected, then the line in error is highlighted, and it jumps to it to save time (no need to search the line).

How do I view a .py code?

To view the source you can open a . py file with IDLE (which comes with Python) or even Notepad although a more advanced text editor or IDE is recommended. See Is there a good, free Python IDE for Windows for IDE recommendations by the stackoverflow community.

How do I make sure Python script is running?

Since your script runs on windows, you can use the Microsoft Task Scheduler (which is installed with Windows) to start your Python script when your computer starts up. If you do not use the cmd window, you can change your Python script extention from . py to . pyw to run the script without a terminal window.


1 Answers

You can check the syntax by compiling it:

python -m py_compile script.py 
like image 130
Mark Johnson Avatar answered Oct 07 '22 09:10

Mark Johnson