RUVIDEO
Поделитесь видео 🙏

3.5 Python Modules and Packages I

What is module?
• A module is a file with .py extension, containing Python definitions and statements that can be used as script or in interactive mode of the interpreter. • Definitions from a module can be imported into other modules or into the main module. • Modules are reusable and organize better management of code blocks.
Executing modules as scripts
Standard modules • Python comes with a library of standard modules called as Python Library Reference. • Built-in or custom modules enhance operational efficiency by providing access to OS systems calls.
Python Libraries
• Python standard libraries provide tools suited to many tasks. • The Python Package Index (PyPI) is the official repository for third-party Python software. • PyPi includes growing collection (from individual programs and modules to packages and entire application development frameworks), in addition to the standard libraries.
Python standard libraries • Built-in Functions • Built-in Constants • Built-in Types • Built-in Exceptions • Text Processing Services • Data Types • Num and Math Modules • Functional Prog Modules • File and Directory Access • Data Persistence • Data Compr and Archiving • File Format • Cryptographic Services • Concurrent Execution • Network and Interprocess Communication • Internet Data Handling • Struc Markup Proc Tools • Int Protocols and Support • Multimedia Services • Internationalization • Program Frameworks • GUI with Tk • Development Tools • Debugging and Profiling • Sw Packaging and Distribution • Python Runtime Services • Custom Python Interpreters • Importing Modules • Python Language Services • MS Windows Specific Services • Unix Specific Services
Python interpreter
Module – code in .py file
Dir() function • The built-in function dir() is used to find out which names a module defines. It returns a sorted list of strings: • It lists all types of names: variables, modules, functions, etc.

Compiled Python files (.pyc) • To speed up loading modules, Python caches the compiled version of each module in the __pycache__ directory under the name module.version.pyc. • In CPython the compiled version of fun123.py would be cached as __pycache__/fun123.cpython-37.pyc.
Compiled Python files (.pyc)
• Python checks the modification date of the source against the compiled version to see if it’s out of date and needs to be recompiled. • This is a completely automatic process. Also, the compiled modules are platform-independent, so the same library can be shared among systems with different architectures.
• Python does not check the cache in two circumstances. – First, it always recompiles and does not store the result for the module that’s loaded directly from the command line. – Second, it does not check the cache if there is no source module. • To support a non-source (compiled only) distribution, the compiled module must be in the source directory, and there must not be a source module.
Optimized modules
• You can use the -O or -OO switches on the Python command to reduce the size of a compiled module. – -O switch removes assert statements, – -OO switch removes both assert statements and __doc__ strings. • “Optimized” modules have an opt- tag and are usually smaller.
• A program doesn’t run any faster when it is read from a .pyc file than when it is read from a .py file; the only thing that’s faster about .pyc files is the speed with which they are loaded. • The module compileall can create .pyc files for all modules in a directory. • There is more detail on this process, including a flow chart of the decisions, in PEP 3147.
PEP 3147 - PYC Repository Directories
• CPython compiles its source code into "byte code", and for performance reasons, it caches this byte code on the file system whenever the source file has changes. This makes loading of Python modules much faster because the compilation phase can be bypassed.
https://www.python.org/dev/peps/pep-3147/

Package Initialization __init__.py
• A file named __init__.py is created with initialization information in package directory. • When a package is imported __init__.py is checked first for the initialization code in the package. • Good practice to add __init__.py file to a package. It may be empty or may contain initialization code.
• if the __init__.py file contains ‘__all__’ defined with list of all modules, import * imports all modules in that list. • Modules can be imported in a package by defining __init__ with __all__ = [list] of all modules OR Import each separately.
Package Initialization __init__.py
Import module • Import a module to use its variables, statements and functions defined in that. • dir() does not list the names of built-in functions and variables by default. • import * is used for a module, all objects from the module are imported into the local symbol table, except those whose names begin with an underscore.

Что делает видео по-настоящему запоминающимся? Наверное, та самая атмосфера, которая заставляет забыть о времени. Когда вы заходите на RUVIDEO, чтобы посмотреть онлайн «3.5 Python Modules and Packages I», вы рассчитываете на нечто большее, чем просто загрузку плеера. И мы это понимаем. Контент такого уровня заслуживает того, чтобы его смотрели в HD 1080, без дрожания картинки и бесконечного буферизации.

Честно говоря, Rutube сегодня — это кладезь уникальных находок, которые часто теряются в общем шуме. Мы же вытаскиваем на поверхность самое интересное. Будь то динамичный экшн, глубокий разбор темы от любимого автора или просто уютное видео для настроения — всё это доступно здесь бесплатно и без лишних формальностей. Никаких «заполните анкету, чтобы продолжить». Только вы, ваш экран и качественный поток.

Если вас зацепило это видео, не забудьте взглянуть на похожие материалы в блоке справа. Мы откалибровали наши алгоритмы так, чтобы они подбирали контент не просто «по тегам», а по настроению и смыслу. Ведь в конечном итоге, онлайн-кинотеатр — это не склад файлов, а место, где каждый вечер можно найти свою историю. Приятного вам отдыха на RUVIDEO!

Видео взято из открытых источников Rutube. Если вы правообладатель, обратитесь к первоисточнику.