import
keyword.py
”) with
some code
calculator.py
class Calculator:
def __init__(self):
pass
def cube(self, x):
return x * x * x
def square(self, x):
return x * x
modules
__init__.py
file
calculator.py
calculator.py
can be imported by
using:Calculator
classas
keywordCalculator
could become
Calc
python3 filename.py < arguments >
sys
module
argv
methodif __name__ == "__main__":
import sys
from modules.calculator import Calculator
print(f"Cube of {int(sys.argv[1])} = {Calculator().cube(int(sys.argv[1]))}")
$ python3 math.py 2
Cube of 2 = 8
platform
, os
and
sys
systemDetails = Windows
dir()
function can be usedmoduleDetails = [’_Processor’, ’_WIN32_CLIENT_RELEASES’, ’_WIN32_SERVER_RELEASES’, ‘builtins’, ‘cached’, ‘copyright’, ‘doc’, ‘file’, ‘loader’, ‘name’, ‘package’, ‘spec’, ‘version’, ’_comparable_version’, ’_component_re’, ’_default_architecture’, ’_follow_symlinks’, ’_get_machine_win32’, ’_ironpython26_sys_version_parser’, ’_ironpython_sys_version_parser’, ’_java_getprop’, ’_libc_search’, ’_mac_ver_xml’, ’_node’, ’_norm_version’, ’_os_release_cache’, ’_os_release_candidates’, ’_os_release_line’, ’_os_release_unescape’, ’_parse_os_release’, ’_platform’, ’_platform_cache’, ’_pypy_sys_version_parser’, ’_sys_version’, ’_sys_version_cache’, ’_sys_version_parser’, ’_syscmd_file’, ’_syscmd_ver’, ’_uname_cache’, ’_unknown_as_blank’, ’_ver_output’, ’_ver_stages’, ‘architecture’, ‘collections’, ‘freedesktop_os_release’, ‘functools’, ‘itertools’, ‘java_ver’, ‘libc_ver’, ‘mac_ver’, ‘machine’, ‘node’, ‘os’, ‘platform’, ‘processor’, ‘python_branch’, ‘python_build’, ‘python_compiler’, ‘python_implementation’, ‘python_revision’, ‘python_version’, ‘python_version_tuple’, ‘re’, ‘release’, ‘subprocess’, ‘sys’, ‘system’, ‘system_alias’, ‘uname’, ‘uname_result’, ‘version’, ‘win32_edition’, ‘win32_is_iot’, ‘win32_ver’]
dir()
function
can be used on all modules
help()
to find out
information about the module