Beruflich Dokumente
Kultur Dokumente
v 1.0
Python Modules
Importare modul
1. import module_name
>>>import math
>>>math.pi
Out[2]: 3.141592653589793
>>> print(sqrt(pi))
1.7724538509055159
>>> print(sin(pi))
1.2246467991473532e-16
>>> sin(3)
0.1411200080598672
>>> sin(3)
0.14112000805986721
>>> m.pi
3.141592653589793
>>> dir(math)
import imp
imp.load_source('mod1','/home/andrei/lab/mod1.py')
https://pymotw.com/3/
>>> help('modules')
sys module
name='cpython', version=sys.version_info(major=3,
minor=5, micro=2, releaselevel='final', serial=0))
Lab:
os module
Executare comenzi
>>> import os
>>> os.system('date')
Fri Oct 20 15:55:13 EEST 2017
0
>>> os.system('cat /etc/lsb-realese')
cat: /etc/lsb-realese: No such file or directory
256
>>> import os
>>> cwd = os.getcwd()
>>> print(cwd)
>>> os.path.isfile('/etc/passwd')
True
>>> os.path.isdir('/tmp')
True
#returns True if path (dir or file) exists else False
os.path.exists(path)
shutil module
random Module
https://en.wikipedia.org/wiki/Applications_of_randomn
ess