|
|
|
@ -1,306 +0,0 @@
|
|
|
|
# Отчет по Теме 8
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Похил Анастасия, А-02-23
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 1 Запуск IDLE
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 2 Создание и использование модулей в среде Python
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 2.1. Запуск модуля на выполнение путем его импорта.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
В данном пункте используется модуль Mod1, находящийся в рабочем каталоге.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
perm1=input('Mod1:Введите значение = ')
|
|
|
|
|
|
|
|
Mod1:Введите значение = 12
|
|
|
|
|
|
|
|
print('Mod1:Значение perm1=',perm1)
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 12
|
|
|
|
|
|
|
|
import Mod1
|
|
|
|
|
|
|
|
Mod1:Введите значение = 12
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 12
|
|
|
|
|
|
|
|
import Mod1
|
|
|
|
|
|
|
|
type(Mod1)
|
|
|
|
|
|
|
|
<class 'module'>
|
|
|
|
|
|
|
|
dir(Mod1)
|
|
|
|
|
|
|
|
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'perm1']
|
|
|
|
|
|
|
|
Mod1.perm1
|
|
|
|
|
|
|
|
'12'
|
|
|
|
|
|
|
|
import Mod1
|
|
|
|
|
|
|
|
importlib.reload(Mod1)
|
|
|
|
|
|
|
|
Mod1:Введите значение = 3
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 3
|
|
|
|
|
|
|
|
<module 'Mod1' from 'C:\\Users\\Настя\\Desktop\\python-labs\\TEMA8\\Mod1.py'>
|
|
|
|
|
|
|
|
Mod1.perm1
|
|
|
|
|
|
|
|
'3'
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 2.2 Значение атрибута sys.modules
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
print(sorted(sys.modules.keys()))
|
|
|
|
|
|
|
|
['Mod1', '__future__', '__main__', '_abc', '_ast', '_bisect', '_bz2', '_codecs', '_collections', '_collections_abc', '_colorize', '_compat_pickle', '_compression', '_datetime', '_frozen_importlib', '_frozen_importlib_external', '_functools', '_heapq', '_imp', '_io', '_lzma', '_opcode', '_opcode_metadata', '_operator', '_pickle', '_pyrepl', '_pyrepl.pager', '_queue', '_random', '_signal', '_sitebuiltins', '_socket', '_sre', '_stat', '_string', '_struct', '_sysconfig', '_thread', '_tkinter', '_tokenize', '_typing', '_warnings', '_weakref', '_weakrefset', '_winapi', '_wmi', 'abc', 'ast', 'bdb', 'binascii', 'bisect', 'builtins', 'bz2', 'codecs', 'collections', 'collections.abc', 'configparser', 'contextlib', 'copyreg', 'datetime', 'dis', 'encodings', 'encodings.aliases', 'encodings.cp1251', 'encodings.utf_8', 'enum', 'errno', 'fnmatch', 'functools', 'genericpath', 'heapq', 'idlelib', 'idlelib.autocomplete', 'idlelib.autocomplete_w', 'idlelib.calltip', 'idlelib.calltip_w', 'idlelib.config', 'idlelib.debugger', 'idlelib.debugger_r', 'idlelib.debugobj', 'idlelib.debugobj_r', 'idlelib.hyperparser', 'idlelib.iomenu', 'idlelib.macosx', 'idlelib.multicall', 'idlelib.pyparse', 'idlelib.rpc', 'idlelib.run', 'idlelib.scrolledlist', 'idlelib.stackviewer', 'idlelib.tooltip', 'idlelib.tree', 'idlelib.util', 'idlelib.window', 'idlelib.zoomheight', 'importlib', 'importlib._abc', 'importlib._bootstrap', 'importlib._bootstrap_external', 'importlib.machinery', 'importlib.util', 'inspect', 'io', 'ipaddress', 'itertools', 'keyword', 'linecache', 'lzma', 'marshal', 'math', 'nt', 'ntpath', 'opcode', 'operator', 'os', 'os.path', 'pickle', 'pkgutil', 'platform', 'plistlib', 'posixpath', 'pydoc', 'pyexpat', 'pyexpat.errors', 'pyexpat.model', 'queue', 'random', 're', 're._casefix', 're._compiler', 're._constants', 're._parser', 'reprlib', 'select', 'selectors', 'shlex', 'shutil', 'site', 'socket', 'socketserver', 'stat', 'string', 'struct', 'sys', 'sysconfig', 'tempfile', 'textwrap', 'threading', 'time', 'tkinter', 'tkinter.constants', 'token', 'tokenize', 'traceback', 'types', 'typing', 'urllib', 'urllib.parse', 'warnings', 'weakref', 'winreg', 'xml', 'xml.parsers', 'xml.parsers.expat', 'xml.parsers.expat.errors', 'xml.parsers.expat.model', 'zipimport', 'zlib']
|
|
|
|
|
|
|
|
sys.modules.pop('Mod1')
|
|
|
|
|
|
|
|
<module 'Mod1' from 'C:\\Users\\Настя\\Desktop\\python-labs\\TEMA8\\Mod1.py'>
|
|
|
|
|
|
|
|
print(sorted(sys.modules.keys()))
|
|
|
|
|
|
|
|
['__future__', '__main__', '_abc', '_ast', '_bisect', '_bz2', '_codecs', '_collections', '_collections_abc', '_colorize', '_compat_pickle', '_compression', '_datetime', '_frozen_importlib', '_frozen_importlib_external', '_functools', '_heapq', '_imp', '_io', '_lzma', '_opcode', '_opcode_metadata', '_operator', '_pickle', '_pyrepl', '_pyrepl.pager', '_queue', '_random', '_signal', '_sitebuiltins', '_socket', '_sre', '_stat', '_string', '_struct', '_sysconfig', '_thread', '_tkinter', '_tokenize', '_typing', '_warnings', '_weakref', '_weakrefset', '_winapi', '_wmi', 'abc', 'ast', 'bdb', 'binascii', 'bisect', 'builtins', 'bz2', 'codecs', 'collections', 'collections.abc', 'configparser', 'contextlib', 'copyreg', 'datetime', 'dis', 'encodings', 'encodings.aliases', 'encodings.cp1251', 'encodings.utf_8', 'enum', 'errno', 'fnmatch', 'functools', 'genericpath', 'heapq', 'idlelib', 'idlelib.autocomplete', 'idlelib.autocomplete_w', 'idlelib.calltip', 'idlelib.calltip_w', 'idlelib.config', 'idlelib.debugger', 'idlelib.debugger_r', 'idlelib.debugobj', 'idlelib.debugobj_r', 'idlelib.hyperparser', 'idlelib.iomenu', 'idlelib.macosx', 'idlelib.multicall', 'idlelib.pyparse', 'idlelib.rpc', 'idlelib.run', 'idlelib.scrolledlist', 'idlelib.stackviewer', 'idlelib.tooltip', 'idlelib.tree', 'idlelib.util', 'idlelib.window', 'idlelib.zoomheight', 'importlib', 'importlib._abc', 'importlib._bootstrap', 'importlib._bootstrap_external', 'importlib.machinery', 'importlib.util', 'inspect', 'io', 'ipaddress', 'itertools', 'keyword', 'linecache', 'lzma', 'marshal', 'math', 'nt', 'ntpath', 'opcode', 'operator', 'os', 'os.path', 'pickle', 'pkgutil', 'platform', 'plistlib', 'posixpath', 'pydoc', 'pyexpat', 'pyexpat.errors', 'pyexpat.model', 'queue', 'random', 're', 're._casefix', 're._compiler', 're._constants', 're._parser', 'reprlib', 'select', 'selectors', 'shlex', 'shutil', 'site', 'socket', 'socketserver', 'stat', 'string', 'struct', 'sys', 'sysconfig', 'tempfile', 'textwrap', 'threading', 'time', 'tkinter', 'tkinter.constants', 'token', 'tokenize', 'traceback', 'types', 'typing', 'urllib', 'urllib.parse', 'warnings', 'weakref', 'winreg', 'xml', 'xml.parsers', 'xml.parsers.expat', 'xml.parsers.expat.errors', 'xml.parsers.expat.model', 'zipimport', 'zlib']
|
|
|
|
|
|
|
|
import Mod1
|
|
|
|
|
|
|
|
Mod1:Введите значение = 10
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 10
|
|
|
|
|
|
|
|
sys.modules.pop('Mod1')
|
|
|
|
|
|
|
|
<module 'Mod1' from 'C:\\Users\\Настя\\Desktop\\python-labs\\TEMA8\\Mod1.py'>
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 2.3. Запуск модуля на выполнение с помощью функции exec().
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
exec(open('Mod1.py').read())
|
|
|
|
|
|
|
|
Mod1:Введите значение = 12
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 12
|
|
|
|
|
|
|
|
exec(open('Mod1.py', encoding='utf-8').read())
|
|
|
|
|
|
|
|
Mod1:Введите значение = 11
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 11
|
|
|
|
|
|
|
|
exec(open('Mod1.py', encoding='utf-8').read())
|
|
|
|
|
|
|
|
Mod1:Введите значение = 3
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 3
|
|
|
|
|
|
|
|
perm1
|
|
|
|
|
|
|
|
'3'
|
|
|
|
|
|
|
|
exec(open('Mod1.py', encoding='utf-8').read())
|
|
|
|
|
|
|
|
Mod1:Введите значение = 4
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 4
|
|
|
|
|
|
|
|
perm1
|
|
|
|
|
|
|
|
'4'
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 2.4. Использование инструкции from … import …
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Пример 1
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
from Mod1 import perm1
|
|
|
|
|
|
|
|
Mod1:Введите значение = 9
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 9
|
|
|
|
|
|
|
|
perm1
|
|
|
|
|
|
|
|
'9'
|
|
|
|
|
|
|
|
dir()
|
|
|
|
|
|
|
|
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'importlib', 'os', 'perm1', 'sys']
|
|
|
|
|
|
|
|
print(sorted(sys.modules.keys()))
|
|
|
|
|
|
|
|
['Mod1', '__future__', '__main__', '_abc', '_ast', '_bisect', '_bz2', '_codecs', '_collections', '_collections_abc', '_colorize', '_compat_pickle', '_compression', '_datetime', '_frozen_importlib', '_frozen_importlib_external', '_functools', '_heapq', '_imp', '_io', '_lzma', '_opcode', '_opcode_metadata', '_operator', '_pickle', '_pyrepl', '_pyrepl.pager', '_queue', '_random', '_signal', '_sitebuiltins', '_socket', '_sre', '_stat', '_string', '_struct', '_sysconfig', '_thread', '_tkinter', '_tokenize', '_typing', '_warnings', '_weakref', '_weakrefset', '_winapi', '_wmi', 'abc', 'ast', 'bdb', 'binascii', 'bisect', 'builtins', 'bz2', 'codecs', 'collections', 'collections.abc', 'configparser', 'contextlib', 'copyreg', 'datetime', 'dis', 'encodings', 'encodings.aliases', 'encodings.cp1251', 'encodings.utf_8', 'enum', 'errno', 'fnmatch', 'functools', 'genericpath', 'heapq', 'idlelib', 'idlelib.autocomplete', 'idlelib.autocomplete_w', 'idlelib.calltip', 'idlelib.calltip_w', 'idlelib.config', 'idlelib.debugger', 'idlelib.debugger_r', 'idlelib.debugobj', 'idlelib.debugobj_r', 'idlelib.hyperparser', 'idlelib.iomenu', 'idlelib.macosx', 'idlelib.multicall', 'idlelib.pyparse', 'idlelib.rpc', 'idlelib.run', 'idlelib.scrolledlist', 'idlelib.stackviewer', 'idlelib.tooltip', 'idlelib.tree', 'idlelib.util', 'idlelib.window', 'idlelib.zoomheight', 'importlib', 'importlib._abc', 'importlib._bootstrap', 'importlib._bootstrap_external', 'importlib.machinery', 'importlib.util', 'inspect', 'io', 'ipaddress', 'itertools', 'keyword', 'linecache', 'lzma', 'marshal', 'math', 'nt', 'ntpath', 'opcode', 'operator', 'os', 'os.path', 'pickle', 'pkgutil', 'platform', 'plistlib', 'posixpath', 'pydoc', 'pyexpat', 'pyexpat.errors', 'pyexpat.model', 'queue', 'random', 're', 're._casefix', 're._compiler', 're._constants', 're._parser', 'reprlib', 'select', 'selectors', 'shlex', 'shutil', 'site', 'socket', 'socketserver', 'stat', 'string', 'struct', 'sys', 'sysconfig', 'tempfile', 'textwrap', 'threading', 'time', 'tkinter', 'tkinter.constants', 'token', 'tokenize', 'traceback', 'types', 'typing', 'urllib', 'urllib.parse', 'warnings', 'weakref', 'winreg', 'xml', 'xml.parsers', 'xml.parsers.expat', 'xml.parsers.expat.errors', 'xml.parsers.expat.model', 'zipimport', 'zlib']
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Как видно, в памяти объекта Mod1 нет, но в sys.modules.keys() появился. Кроме того, в рабочем пространстве появился объект perm1, импортированный из модуля, поэтому к нему можно обращаться по имени perm1.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Пример 2
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
from Mod2 import beta
|
|
|
|
|
|
|
|
g=beta(2)
|
|
|
|
|
|
|
|
****BETA****
|
|
|
|
|
|
|
|
g
|
|
|
|
|
|
|
|
535.4916555247646
|
|
|
|
|
|
|
|
dir()
|
|
|
|
|
|
|
|
['__annotations__', '__builtins__', '__doc__', '__loader__', '__name__', '__package__', '__spec__', 'beta', 'g', 'importlib', 'os', 'perm1', 'sys']
|
|
|
|
|
|
|
|
print(sorted(sys.modules.keys()))
|
|
|
|
|
|
|
|
['Mod1', 'Mod2', '__future__', '__main__', '_abc', '_ast', '_bisect', '_bz2', '_codecs', '_collections', '_collections_abc', '_colorize', '_compat_pickle', '_compression', '_datetime', '_frozen_importlib', '_frozen_importlib_external', '_functools', '_heapq', '_imp', '_io', '_lzma', '_opcode', '_opcode_metadata', '_operator', '_pickle', '_pyrepl', '_pyrepl.pager', '_queue', '_random', '_signal', '_sitebuiltins', '_socket', '_sre', '_stat', '_string', '_struct', '_sysconfig', '_thread', '_tkinter', '_tokenize', '_typing', '_warnings', '_weakref', '_weakrefset', '_winapi', '_wmi', 'abc', 'ast', 'bdb', 'binascii', 'bisect', 'builtins', 'bz2', 'codecs', 'collections', 'collections.abc', 'configparser', 'contextlib', 'copyreg', 'datetime', 'dis', 'encodings', 'encodings.aliases', 'encodings.cp1251', 'encodings.utf_8', 'enum', 'errno', 'fnmatch', 'functools', 'genericpath', 'heapq', 'idlelib', 'idlelib.autocomplete', 'idlelib.autocomplete_w', 'idlelib.calltip', 'idlelib.calltip_w', 'idlelib.config', 'idlelib.debugger', 'idlelib.debugger_r', 'idlelib.debugobj', 'idlelib.debugobj_r', 'idlelib.hyperparser', 'idlelib.iomenu', 'idlelib.macosx', 'idlelib.multicall', 'idlelib.pyparse', 'idlelib.rpc', 'idlelib.run', 'idlelib.scrolledlist', 'idlelib.stackviewer', 'idlelib.tooltip', 'idlelib.tree', 'idlelib.util', 'idlelib.window', 'idlelib.zoomheight', 'importlib', 'importlib._abc', 'importlib._bootstrap', 'importlib._bootstrap_external', 'importlib.machinery', 'importlib.util', 'inspect', 'io', 'ipaddress', 'itertools', 'keyword', 'linecache', 'lzma', 'marshal', 'math', 'nt', 'ntpath', 'opcode', 'operator', 'os', 'os.path', 'pickle', 'pkgutil', 'platform', 'plistlib', 'posixpath', 'pydoc', 'pyexpat', 'pyexpat.errors', 'pyexpat.model', 'queue', 'random', 're', 're._casefix', 're._compiler', 're._constants', 're._parser', 'reprlib', 'select', 'selectors', 'shlex', 'shutil', 'site', 'socket', 'socketserver', 'stat', 'string', 'struct', 'sys', 'sysconfig', 'tempfile', 'textwrap', 'threading', 'time', 'tkinter', 'tkinter.constants', 'token', 'tokenize', 'traceback', 'types', 'typing', 'urllib', 'urllib.parse', 'warnings', 'weakref', 'winreg', 'xml', 'xml.parsers', 'xml.parsers.expat', 'xml.parsers.expat.errors', 'xml.parsers.expat.model', 'zipimport', 'zlib']
|
|
|
|
|
|
|
|
alpha()
|
|
|
|
|
|
|
|
Traceback (most recent call last):
|
|
|
|
|
|
|
|
File "<pyshell#30>", line 1, in <module>
|
|
|
|
|
|
|
|
alpha()
|
|
|
|
|
|
|
|
NameError: name 'alpha' is not defined
|
|
|
|
|
|
|
|
from Mod2 import alpha as al
|
|
|
|
|
|
|
|
al()
|
|
|
|
|
|
|
|
****ALPHA****
|
|
|
|
|
|
|
|
Значение t=2
|
|
|
|
|
|
|
|
'2'
|
|
|
|
|
|
|
|
del al,beta
|
|
|
|
|
|
|
|
from Mod2 import alpha as al, beta as bt
|
|
|
|
|
|
|
|
del al,bt
|
|
|
|
|
|
|
|
from Mod2 import *
|
|
|
|
|
|
|
|
tt=alpha()
|
|
|
|
|
|
|
|
****ALPHA****
|
|
|
|
|
|
|
|
Значение t=0.12
|
|
|
|
|
|
|
|
uu=beta(float(tt))
|
|
|
|
|
|
|
|
****BETA****
|
|
|
|
|
|
|
|
uu
|
|
|
|
|
|
|
|
1.4578913609506803
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
## 3. Создание многомодульных программ.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 3.1. Простая многомодульная программа.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
sys.modules.pop('Mod1')
|
|
|
|
|
|
|
|
<module 'Mod1' from 'C:\\Users\\Настя\\Desktop\\python-labs\\TEMA8\\Mod1.py'>
|
|
|
|
|
|
|
|
sys.modules.pop('Mod2')
|
|
|
|
|
|
|
|
<module 'Mod2' from 'C:\\Users\\Настя\\Desktop\\python-labs\\TEMA8\\Mod2.py'>
|
|
|
|
|
|
|
|
print(sorted(sys.modules.keys()))
|
|
|
|
|
|
|
|
['__future__', '__main__', '_abc', '_ast', '_bisect', '_bz2', '_codecs', '_collections', '_collections_abc', '_colorize', '_compat_pickle', '_compression', '_datetime', '_frozen_importlib', '_frozen_importlib_external', '_functools', '_heapq', '_imp', '_io', '_lzma', '_opcode', '_opcode_metadata', '_operator', '_pickle', '_pyrepl', '_pyrepl.pager', '_queue', '_random', '_signal', '_sitebuiltins', '_socket', '_sre', '_stat', '_string', '_struct', '_sysconfig', '_thread', '_tkinter', '_tokenize', '_typing', '_warnings', '_weakref', '_weakrefset', '_winapi', '_wmi', 'abc', 'ast', 'bdb', 'binascii', 'bisect', 'builtins', 'bz2', 'codecs', 'collections', 'collections.abc', 'configparser', 'contextlib', 'copyreg', 'datetime', 'dis', 'encodings', 'encodings.aliases', 'encodings.cp1251', 'encodings.utf_8', 'enum', 'errno', 'fnmatch', 'functools', 'genericpath', 'heapq', 'idlelib', 'idlelib.autocomplete', 'idlelib.autocomplete_w', 'idlelib.calltip', 'idlelib.calltip_w', 'idlelib.config', 'idlelib.debugger', 'idlelib.debugger_r', 'idlelib.debugobj', 'idlelib.debugobj_r', 'idlelib.hyperparser', 'idlelib.iomenu', 'idlelib.macosx', 'idlelib.multicall', 'idlelib.pyparse', 'idlelib.rpc', 'idlelib.run', 'idlelib.scrolledlist', 'idlelib.stackviewer', 'idlelib.tooltip', 'idlelib.tree', 'idlelib.util', 'idlelib.window', 'idlelib.zoomheight', 'importlib', 'importlib._abc', 'importlib._bootstrap', 'importlib._bootstrap_external', 'importlib.machinery', 'importlib.util', 'inspect', 'io', 'ipaddress', 'itertools', 'keyword', 'linecache', 'lzma', 'marshal', 'math', 'nt', 'ntpath', 'opcode', 'operator', 'os', 'os.path', 'pickle', 'pkgutil', 'platform', 'plistlib', 'posixpath', 'pydoc', 'pyexpat', 'pyexpat.errors', 'pyexpat.model', 'queue', 'random', 're', 're._casefix', 're._compiler', 're._constants', 're._parser', 'reprlib', 'select', 'selectors', 'shlex', 'shutil', 'site', 'socket', 'socketserver', 'stat', 'string', 'struct', 'sys', 'sysconfig', 'tempfile', 'textwrap', 'threading', 'time', 'tkinter', 'tkinter.constants', 'token', 'tokenize', 'traceback', 'types', 'typing', 'urllib', 'urllib.parse', 'warnings', 'weakref', 'winreg', 'xml', 'xml.parsers', 'xml.parsers.expat', 'xml.parsers.expat.errors', 'xml.parsers.expat.model', 'zipimport', 'zlib']
|
|
|
|
|
|
|
|
import Mod0
|
|
|
|
|
|
|
|
Mod1:Введите значение = 5
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 5
|
|
|
|
|
|
|
|
perm1= 5
|
|
|
|
|
|
|
|
****ALPHA****
|
|
|
|
|
|
|
|
Значение t=23
|
|
|
|
|
|
|
|
tt= 23
|
|
|
|
|
|
|
|
****BETA****
|
|
|
|
|
|
|
|
qq= 2.402459849485247e+31
|
|
|
|
|
|
|
|
Mod0.tt; Mod0.qq; Mod0.Mod1.perm1
|
|
|
|
|
|
|
|
'23'
|
|
|
|
|
|
|
|
2.402459849485247e+31
|
|
|
|
|
|
|
|
'5'
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 3.2. Еще один пример.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
import MM0
|
|
|
|
|
|
|
|
k1,T,k2,Xm,A,F,N=10,5,20,0.2,4,0.002,45
|
|
|
|
|
|
|
|
y= [0, 0, 0, 0, 0, 0, 0, 0, 0, -1.319802644385577, 46.01934525453105, -1405.3955775891707, 42745.94702692066, -1299970.5133264635, 39533945.50140401, -1202283133.3347626, 36563128408.478745, -1111936383153.658, 33815556107824.71, -1028378828326575.4, 3.1274452834020396e+16, -9.511002882653281e+17, 2.892430326884485e+19, -8.796289202203655e+20, 2.675075800776401e+22, -8.135283385301572e+23, 2.474054594638224e+25, -7.523949501635715e+26, 2.288139325051647e+28, -6.958554904853609e+29, 2.1161948415343663e+31, -6.435647441989787e+32, 1.9571712956052526e+34, -5.952034375513921e+35, 1.810097730681449e+37, -5.504762889302416e+38, 1.6740761536689568e+40, -5.091102059507955e+41, 1.548276052049398e+43, -4.708526180245838e+44, 1.4319293229856865e+46, -4.354699342288017e+47, 1.3243255834850482e+49, -4.02746117060638e+50, 1.2248078329844667e+52]
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
### 3.3. Области дейтсвия объектов в модулях.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Попробуйте вставить в функции alpha обращение к функции beta и, наоборот, из beta – к alpha.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
def alpha():
|
|
|
|
|
|
|
|
print('****ALPHA****')
|
|
|
|
|
|
|
|
t=input('Значение t=')
|
|
|
|
|
|
|
|
beta(t)
|
|
|
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def beta(q):
|
|
|
|
|
|
|
|
print('****BETA****')
|
|
|
|
|
|
|
|
import math
|
|
|
|
|
|
|
|
expi=q*math.pi
|
|
|
|
|
|
|
|
return math.exp(expi)
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
Mod1:Введите значение = 8
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 8
|
|
|
|
|
|
|
|
perm1= 8
|
|
|
|
|
|
|
|
****ALPHA****
|
|
|
|
|
|
|
|
Значение t=6
|
|
|
|
|
|
|
|
tt= 6
|
|
|
|
|
|
|
|
****BETA****
|
|
|
|
|
|
|
|
qq= 153552935.39544657
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
def alpha():
|
|
|
|
|
|
|
|
print('****ALPHA****')
|
|
|
|
|
|
|
|
t=input('Значение t=')
|
|
|
|
|
|
|
|
return t
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def beta(q):
|
|
|
|
|
|
|
|
print('****BETA****')
|
|
|
|
|
|
|
|
import math
|
|
|
|
|
|
|
|
expi=alpha()*math.pi
|
|
|
|
|
|
|
|
return math.exp(expi)
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
Mod1:Введите значение = 5
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 5
|
|
|
|
|
|
|
|
perm1= 5
|
|
|
|
|
|
|
|
****ALPHA****
|
|
|
|
|
|
|
|
Значение t=8
|
|
|
|
|
|
|
|
tt= 8
|
|
|
|
|
|
|
|
****BETA****
|
|
|
|
|
|
|
|
qq= 82226315585.59491
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Попробуйте отобразить на экране в модуле Mod0 значения объектов t и expi.
|
|
|
|
|
|
|
|
Из-за того, что функция alpha() возвращает t, проблем с её отображением нет.
|
|
|
|
|
|
|
|
А вот expi напрямую вывести нельзя, потому что это локальная переменная функции beta() и она не возвращается данной функцией.
|
|
|
|
|
|
|
|
Т.к. возвращаемая переменная qq содержит expi в показателе степени экспоненты, то один из путей решения - проделать обратную операцию (взять натуральный логарифм от qq)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
Mod1:Введите значение = 5
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 5
|
|
|
|
|
|
|
|
perm1= 5
|
|
|
|
|
|
|
|
****ALPHA****
|
|
|
|
|
|
|
|
Значение t=1
|
|
|
|
|
|
|
|
t= 1
|
|
|
|
|
|
|
|
****BETA****
|
|
|
|
|
|
|
|
Traceback (most recent call last):
|
|
|
|
|
|
|
|
File "C:/Users/Настя/Desktop/python-labs/TEMA8/Mod0_copy.py", line 9, in <module>
|
|
|
|
|
|
|
|
print('expi=', Mod2.expi)
|
|
|
|
|
|
|
|
NameError: name 'Mod2' is not defined. Did you mean: 'Mod1'?
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
#Модуль Mod0
|
|
|
|
|
|
|
|
import Mod1, math
|
|
|
|
|
|
|
|
print('perm1=',Mod1.perm1)
|
|
|
|
|
|
|
|
from Mod2 import alpha as al
|
|
|
|
|
|
|
|
tt=al()
|
|
|
|
|
|
|
|
print('t=',tt)
|
|
|
|
|
|
|
|
from Mod2 import beta
|
|
|
|
|
|
|
|
qq=beta(float(tt))
|
|
|
|
|
|
|
|
print('expi=', math.log(qq))
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
Mod1:Введите значение = 6
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 6
|
|
|
|
|
|
|
|
perm1= 6
|
|
|
|
|
|
|
|
****ALPHA****
|
|
|
|
|
|
|
|
Значение t=1
|
|
|
|
|
|
|
|
t= 1
|
|
|
|
|
|
|
|
****BETA****
|
|
|
|
|
|
|
|
expi= 3.141592653589793
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Попробуйте в модуле Mod0 увеличить в 3 раза значение объекта perm1 и отобразить его после этого на экране.
|
|
|
|
|
|
|
|
Т.к. perm1 имеет строковый тип, то без приведения к целочисленному типу при умножении будет повторение введённого значения 3 раза.
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
#Модуль Mod0
|
|
|
|
|
|
|
|
import Mod1, math
|
|
|
|
|
|
|
|
print('perm1=',Mod1.perm1)
|
|
|
|
|
|
|
|
print('3*perm1=', 3*Mod1.perm1)
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
Mod1:Введите значение = 3
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 3
|
|
|
|
|
|
|
|
perm1= 3
|
|
|
|
|
|
|
|
3*perm1= 333
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
#Модуль Mod0
|
|
|
|
|
|
|
|
import Mod1, math
|
|
|
|
|
|
|
|
print('perm1=',Mod1.perm1)
|
|
|
|
|
|
|
|
print('3*perm1=', 3*int(Mod1.perm1))
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
Mod1:Введите значение = 3
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 3
|
|
|
|
|
|
|
|
perm1= 3
|
|
|
|
|
|
|
|
3*perm1= 9
|
|
|
|
|
|
|
|
```
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Попробуйте в командной строке (в главном модуле) увеличить в 2 раза значения объектов perm1, tt, qq.
|
|
|
|
|
|
|
|
Из-за того, что perm1 и tt представлены изначально в строковом виде, то ситуация будет такой же, как и ранее. При необходимости их можно предварительно перевести в целочисленный тип
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
```py
|
|
|
|
|
|
|
|
import Mod0
|
|
|
|
|
|
|
|
Mod1:Введите значение = 1
|
|
|
|
|
|
|
|
Mod1:Значение perm1= 1
|
|
|
|
|
|
|
|
perm1= 1
|
|
|
|
|
|
|
|
****ALPHA****
|
|
|
|
|
|
|
|
Значение t=1
|
|
|
|
|
|
|
|
tt= 1
|
|
|
|
|
|
|
|
****BETA****
|
|
|
|
|
|
|
|
qq= 23.140692632779267
|
|
|
|
|
|
|
|
Mod0.Mod1.perm1*2
|
|
|
|
|
|
|
|
'11'
|
|
|
|
|
|
|
|
Mod0.tt*2
|
|
|
|
|
|
|
|
'11'
|
|
|
|
|
|
|
|
Mod0.qq*2
|
|
|
|
|
|
|
|
46.281385265558534
|
|
|
|
|
|
|
|
```
|
|
|
|
|