Let's take a look at the Python module import and
[email protected] dist-packages]# cat indentation.py
#!/usr/bin/enb pythonversion = ' v1.0 ' author = ' Madon ' def sayhi (n): print ' Hi, this is a module. ', n
Here is a description of this module I wrote. 2-3 rows of variables used, the user calls version and author output corresponding content.
Line four uses Sayhi to add user input content. Prints the contents of print.
[Email protected] dist-packages]# pwd
/usr/lib/python2.7/dist-packages
[Email protected] dist-packages]#
>>> Import Tab
>>> Import Indentation
>>> indentation.
Indentation.__class__ (indentation.__package__
Indentation.__delattr__ (indentation.__reduce__ (
Indentation.__dict__ indentation.__reduce_ex__ (
Indentation.__doc__ indentation.__repr__ (
indentation.__file__ indentation.__setattr__ (
Indentation.__format__ (indentation.__sizeof__ (
INDENTATION.__GETATTRIBUTE__ (indentation.__str__ (
Indentation.__hash__ (indentation.__subclasshook__ (
Indentation.__init__ (Indentation.author
indentation.__name__ Indentation.sayhi (
indentation.__new__ (indentation.version
>>> indentation.version
' v1.0 '
>>> Indentation.author
' Madon '
>>> indentation.sayhi (' Madon ')
Hi, this is a module. Madon
>>> exit ()
[[Email protected] Di
OS module and directly using the system
>>> Import Tab
>>> Import OS
>>> os.system (' du ')
16.
0
>>> os.system (' DF ')
Filesystem 1k-blocks used Available use% mounted on
/dev/sda3 40771124 1879660 38891464 5%/
Devtmpfs 240200 0 240200 0%/dev
Tmpfs 248952 0 248952 0%/dev/shm
Tmpfs 248952 24964 223988 11%/run
Tmpfs 248952 0 248952 0%/sys/fs/cgroup
/DEV/SDA1 98988 95756 3232 97%/boot
0
>>> from OS import system
>>> system (' DF ')
Filesystem 1k-blocks used Available use% mounted on
/dev/sda3 40771124 1879660 38891464 5%/
Devtmpfs 240200 0 240200 0%/dev
Tmpfs 248952 0 248952 0%/dev/shm
Tmpfs 248952 24964 223988 11%/run
Tmpfs 248952 0 248952 0%/sys/fs/cgroup
/DEV/SDA1 98988 95756 3232 97%/boot
0
>>>
>>> from OS import system as S
>>> s (' DF ')
Filesystem 1k-blocks used Available use% mounted on
/dev/sda3 40771124 1879660 38891464 5%/
Devtmpfs 240200 0 240200 0%/dev
Tmpfs 248952 0 248952 0%/dev/shm
Tmpfs 248952 24964 223988 11%/run
Tmpfs 248952 0 248952 0%/sys/fs/cgroup
/DEV/SDA1 98988 95756 3232 97%/boot
0
>>>
If the module is not found under these paths, it will be an error.
>>> Import Sys
>>> Sys.path
[', '/usr/lib64/python27.zip ', '/usr/lib64/python2.7 ', '/usr/lib64/python2.7/plat-linux2 ', '/usr/lib64/python2.7/ Lib-tk ', '/usr/lib64/python2.7/lib-old ', '/usr/lib64/python2.7/lib-dynload ', '/usr/lib64/python2.7/site-packages ' , '/usr/lib64/python2.7/site-packages/gtk-2.0 ', '/usr/lib/python2.7/site-packages ']
>>>
This article from the "Clear Sky" blog, declined reprint!
Import and use of Python modules