How to run a script from a separate Python file in Python

Running a script from a separate file executes the script without having to physically open the file and run it.

Solution for How to run a script from a separate Python file in Python : You can use exec() to run a script from IDLE interactive shell Call open(file) with a script as file to return a stream. Use file.read() with the stream as file to read it. Call exec(source) with the read file as source to run the script.


how-to-run-a-script-from-a-separate-python-file-in-python