Tutorial for Runpy in Python

The Python programming language has a standard library that contains many useful modules. These modules are usually imported into a source code file to enable the use of their unique functions. You can also launch modules from the command line, which executes special code. This behavior can also be obtained from within a Python source code file using the "runpy" module. The runpy module executes the special code of a module without importing it into your source code file.

Instructions

    • 1

      Open the IDLE text editor that comes with the Python download. The IDLE text editor is in Program Files (or Applications for Macintosh), in the Python directory. A blank source code file opens in the IDLE text editor window.

    • 2

      Import the runpy module using the following statement:

      import runpy

    • 3

      Execute a module using the "runpy.run_module" function. This function launches a module as if it were executed from the command line, but does not import the module. Its functions are inaccessible to the rest of the program unless it is later imported. To use the runpy.run_module function and invoke a module named "moduleName," write the following statement:

      runpy.run_module(moduleName)

    • 4

      Execute the Python program by pressing "F5." The module selected in the previous step is executed from within your program.

Related Searches:

References

Resources

Comments

You May Also Like

  • How to Convert Python to EXE

    The simplest way to create EXE files from Python programs is to use the open source py2exe program hosted on SourceForge. Most...

Related Ads

Featured