Erp Module Pdf

0 views
Skip to first unread message

Meinard Hartmann

unread,
Aug 3, 2024, 5:19:43 PM8/3/24
to plenivalfai

To support this, Python has a way to put definitions in a file and use them in ascript or in an interactive instance of the interpreter. Such a file is called amodule; definitions from a module can be imported into other modules or intothe main module (the collection of variables that you have access to in ascript executed at the top level and in calculator mode).

This does not add the names of the functions defined in fibo directly tothe current namespace (see Python Scopes and Namespaces for more details);it only adds the module name fibo there. Usingthe module name you can access the functions:

A module can contain executable statements as well as function definitions.These statements are intended to initialize the module. They are executed onlythe first time the module name is encountered in an import statement. [1](They are also run if the file is executed as a script.)

This imports all names except those beginning with an underscore (_).In most cases Python programmers do not use this facility since it introducesan unknown set of names into the interpreter, possibly hiding some thingsyou have already defined.

Note that in general the practice of importing * from a module or package isfrowned upon, since it often causes poorly readable code. However, it is okay touse it to save typing in interactive sessions.

On file systems which support symlinks, the directory containing the inputscript is calculated after the symlink is followed. In other words thedirectory containing the symlink is not added to the module search path.

After initialization, Python programs can modify sys.path. Thedirectory containing the script being run is placed at the beginning of thesearch path, ahead of the standard library path. This means that scripts in thatdirectory will be loaded instead of modules of the same name in the librarydirectory. This is an error unless the replacement is intended. See sectionStandard Modules for more information.

To speed up loading modules, Python caches the compiled version of each modulein the __pycache__ directory under the name module.version.pyc,where the version encodes the format of the compiled file; it generally containsthe Python version number. For example, in CPython release 3.3 the compiledversion of spam.py would be cached as __pycache__/spam.cpython-33.pyc. Thisnaming convention allows compiled modules from different releases and differentversions of Python to coexist.

The __init__.py files are required to make Python treat directoriescontaining the file as packages (unless using a namespace package, arelatively advanced feature). This prevents directories with a common name,such as string, from unintentionally hiding valid modules that occur lateron the module search path. In the simplest case, __init__.py can just bean empty file, but it can also execute initialization code for the package orset the __all__ variable, described later.

Note that when using from package import item, the item can be either asubmodule (or subpackage) of the package, or some other name defined in thepackage, like a function, class or variable. The import statement firsttests whether the item is defined in the package; if not, it assumes it is amodule and attempts to load it. If it fails to find it, an ImportErrorexception is raised.

Be aware that submodules might become shadowed by locally defined names. Forexample, if you added a reverse function to thesound/effects/__init__.py file, the from sound.effects import *would only import the two submodules echo and surround, but not thereverse submodule, because it is shadowed by the locally definedreverse function:

If __all__ is not defined, the statement from sound.effects import *does not import all submodules from the package sound.effects into thecurrent namespace; it only ensures that the package sound.effects hasbeen imported (possibly running any initialization code in __init__.py)and then imports whatever names are defined in the package. This includes anynames defined (and submodules explicitly loaded) by __init__.py. Italso includes any submodules of the package that were explicitly loaded byprevious import statements. Consider this code:

In this example, the echo and surround modules are imported in thecurrent namespace because they are defined in the sound.effects packagewhen the from...import statement is executed. (This also works when__all__ is defined.)

Remember, there is nothing wrong with using from package importspecific_submodule! In fact, this is the recommended notation unless theimporting module needs to use submodules with the same name from differentpackages.

When packages are structured into subpackages (as with the sound packagein the example), you can use absolute imports to refer to submodules of siblingspackages. For example, if the module sound.filters.vocoder needs to usethe echo module in the sound.effects package, it can use fromsound.effects import echo.

You can also write relative imports, with the from module import name formof import statement. These imports use leading dots to indicate the current andparent packages involved in the relative import. From the surroundmodule for example, you might use:

Note that relative imports are based on the name of the current module. Sincethe name of the main module is always "__main__", modules intended for useas the main module of a Python application must always use absolute imports.

Files with a .js extension or without an extension, when the nearest parentpackage.json file doesn't contain a top-level field "type" or there isno package.json in any parent folder; unless the file contains syntax thaterrors unless it is evaluated as an ES module. Package authors should includethe "type" field, even in packages where all sources are CommonJS. Beingexplicit about the type of the package will make things easier for buildtools and loaders to determine how the files in the package should beinterpreted.

Files with an extension that is not .mjs, .cjs, .json, .node, or .js(when the nearest parent package.json file contains a top-level field"type" with a value of "module", those files will be recognized asCommonJS modules only if they are being included via require(), not whenused as the command-line entry point of the program).

The semantics of the Node.js require() function were designed to be generalenough to support reasonable directory structures. Package manager programssuch as dpkg, rpm, and npm will hopefully find it possible to buildnative packages from Node.js modules without modification.

Packages can depend on one another. In order to install package foo, itmay be necessary to install a specific version of package bar. The barpackage may itself have dependencies, and in some cases, these may even collideor form cyclic dependencies.

Because Node.js looks up the realpath of any modules it loads (that is, itresolves symlinks) and then looks for their dependencies in node_modules folders,this situation can be resolved with the following architecture:

Furthermore, to make the module lookup process even more optimal, ratherthan putting packages directly in /usr/lib/node, we could put them in/usr/lib/node_modules//. Then Node.js will not botherlooking for missing dependencies in /usr/node_modules or /node_modules.

In order to make modules available to the Node.js REPL, it might be useful toalso add the /usr/lib/node_modules folder to the $NODE_PATH environmentvariable. Since the module lookups using node_modules folders are allrelative, and based on the real path of the files making the calls torequire(), the packages themselves can be anywhere.

The .mjs extension is reserved for ECMAScript Modules.Currently, if the flag --experimental-require-module is not used, loadingan ECMAScript module using require() will throw a ERR_REQUIRE_ESMerror, and users need to use import() instead. SeeDetermining module system section for more inforegarding which files are parsed as ECMAScript modules.

require() will load the requested module as an ES Module, and returnthe module namespace object. In this case it is similar to dynamicimport() but is run synchronously and returns the name space objectdirectly.

For interoperability with existing tools that convert ES Modules into CommonJS,which could then load real ES Modules through require(), the returned namespacewould contain a __esModule: true property if it has a default export so thatconsuming code generated by tools can recognize the default exports in realES Modules. If the namespace already defines __esModule, this would not be added.This property is experimental and can change in the future. It should only be usedby tools converting ES modules into CommonJS modules, following existing ecosystemconventions. Code authored directly in CommonJS should avoid depending on it.

If the module being require()'d contains top-level await, or the modulegraph it imports contains top-level await,ERR_REQUIRE_ASYNC_MODULE will be thrown. In this case, users shouldload the asynchronous module using import().

If --experimental-print-required-tla is enabled, instead of throwingERR_REQUIRE_ASYNC_MODULE before evaluation, Node.js will evaluate themodule, try to locate the top-level awaits, and print their location tohelp users fix them.

Modules are cached after the first time they are loaded. This means (among otherthings) that every call to require('foo') will get exactly the same objectreturned, if it would resolve to the same file.

Provided require.cache is not modified, multiple calls to require('foo')will not cause the module code to be executed multiple times. This is animportant feature. With it, "partially done" objects can be returned, thusallowing transitive dependencies to be loaded even when they would cause cycles.

Modules are cached based on their resolved filename. Since modules may resolveto a different filename based on the location of the calling module (loadingfrom node_modules folders), it is not a guarantee that require('foo') willalways return the exact same object, if it would resolve to different files.

c80f0f1006
Reply all
Reply to author
Forward
0 new messages