python 模块的导入和使用
2015-11-27 11:37
621 查看
来看一看python的模块导入和是用
[root@web-02 dist-packages]# cat indentation.py
//第四行使用sayHi 加用户输入内容。则输出print里面的内容。
[root@web-02 dist-packages]# pwd
/usr/lib/python2.7/dist-packages
[root@web-02 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()
[root@web-02 di
os模块以及直接使用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
>>>
如果模块在这些路径下 没有找到的话,就会报错。
>>> 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']
>>>
本文出自 “晴空” 博客,谢绝转载!
[root@web-02 dist-packages]# cat indentation.py
#!/usr/bin/enb python version = 'v1.0' author = 'Madon' def sayHi (n): print 'hi , this is a module.',n//这里说明一下,我写的这个模块。2-3行使用的变量,用户调用version和author输出对应内容。
//第四行使用sayHi 加用户输入内容。则输出print里面的内容。
[root@web-02 dist-packages]# pwd
/usr/lib/python2.7/dist-packages
[root@web-02 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()
[root@web-02 di
os模块以及直接使用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
>>>
如果模块在这些路径下 没有找到的话,就会报错。
>>> 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']
>>>
本文出自 “晴空” 博客,谢绝转载!
相关文章推荐
- Python程序的执行过程 解释型语言和编译型语言
- Python运行出错情况
- python爬虫——爬取知乎上自己关注的问题
- 《利用python进行数据分析》读书笔记--第四章 numpy基础:数组和矢量计算
- Python-变量
- 安装 python psutil 包
- Python性能鸡汤
- python如何得到13位时间戳?
- 《利用python进行数据分析》读书笔记--第三章 ipython使用
- 每天一点python——八大排序算法的Python实现
- 使用wfastcgi在IIS上部署Python Flask应用
- python nonzero()
- Python 安全类目推荐 (持续更新)
- Bullet:Python的函数中参数是引用吗?
- python的一些常用的标准库
- python 系统监控
- python-30:极视界爬虫V-0.1
- MySQL-python 安装出现的问题
- 使用python批量给设备安装apk
- python下if/for/while用法