Python Forum
compiling but not running source code
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
compiling but not running source code
#1
if it's a function i can just run the "python3" command on that source file and i will get a failure and a message if there is a syntax error. but for commands, if there is no error, then the command is run. i want to do a "syntax check" on a big collection (over 1500) of python source files for my upgrade to 3.8 and i don't want to run any of those checked scripts.

i was thinking of making a script to do this by making a copy of each python script with the line "exit(36)\n" prepended to each, in a temporary file before running python3 on that temporary file. that way, everything will always exit with a specific exit value, instead or running any of the original source code, if it has no errors.

or is there a better way to do this like a python3 command option?
Tradition is peer pressure from dead people

What do you call someone who speaks three languages? Trilingual. Two languages? Bilingual. One language? American.
Reply
#2
Use the builtin function compile(). It does just that: compile and not run.

From the command line, you can also try python -m compileall <options> <args>.
Skaperen likes this post
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  compiling with an undefined variable Skaperen 0 992 Nov-10-2022, 11:59 PM
Last Post: Skaperen
  running produced python code Skaperen 6 1,896 Dec-25-2021, 05:52 PM
Last Post: Skaperen
  compiling numpy, getting C source Skaperen 10 3,680 Nov-20-2021, 12:41 AM
Last Post: Skaperen
  code running after tracebacks Skaperen 0 1,257 Oct-03-2021, 12:09 AM
Last Post: Skaperen
  empty lines in source code Skaperen 6 2,997 Jun-02-2021, 07:11 PM
Last Post: Gribouillis
  python compiling and sql? abrogard 2 2,270 Oct-27-2020, 06:37 AM
Last Post: buran
  Running three-year old python code ErnestTBass 4 2,516 Jun-19-2020, 02:46 PM
Last Post: snippsat
  visual studio code python how to get source code of import module definitian umen 2 3,922 Jun-13-2020, 06:20 PM
Last Post: umen
  Where can I get information about internal logic of source code Python? AlekseyPython 1 2,522 Dec-17-2018, 05:27 AM
Last Post: siripriya
  How do I properly release my code open-source? Brennan 1 2,557 Jun-30-2018, 12:33 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020