panahardware.blogg.se

Download other m switch
Download other m switch







This meant names such as rver were now fully supported. With the completion of PEP 338 the -m feature was extended to support representations beyond the top level. One constraint with this iteration, according to PEP 338, was that -m only worked with top level modulenames (i.e., modules that could be found directly on sys.path without any intervening package modules).

download other m switch

That is, if we knew both the and for a module then the following two commands were equivalent: python and python -m. Initially its only purpose was to provide an alternative means of identifying the python module to execute from the command line. The -m flag was first introduced in Python 2.4.1. On the other hand, if one executes that same package module via import then only the package's _init_.py will be executed. For example, if one executes a package module via python then /_main_.py will be executed. Depending on the execution method (and module type) what code gets evaluated, and when, can change quite a bit. By altering this variable one can change how Python resolves modulenames into filenames (for more on how this is done see PEP 302).Īll modules (both code and package) can be executed (i.e., code associated with the module will be evaluated by the Python interpreter). These rules hinge on the sys.path variable. All python interpreters are able to convert modulenames to filenames by following the same few, well-defined rules. In general, modules are identified by modulename in Python code (e.g., import ) and by filename on the command line (e.g., python ).

download other m switch

Python allows modules to be uniquely identified in two distinct ways: modulename and filename.

download other m switch

The most common type of code modules are *.py files while the most common type of package modules are directories containing an _init_.py file. A package module is a directory that contains other modules (either code modules or package modules). A code module is any file that contains python executable code. Module's come in one of two flavors: code modules and package modules. Python's primary organizational unit is known as a module. To explain the -m flag we first need to explain a little terminology. In short it can be used to: (1) execute python code from the command line via modulename rather than filename (2) add a directory to sys.path for use in import resolution and (3) execute python code that contains relative imports from the command line. The -m flag does a lot of things, not all of which will be needed all the time. Therefore, the following will attempt to improve on what has come before.

download other m switch

Despite this question having been asked and answered several times (e.g., here, here, here, and here), in my opinion no existing answer fully or concisely captures all the implications of the -m flag.









Download other m switch