python-模块系列
-->
模块,用一砣代码实现了某个功能的代码集合。
类似于函数式编程和面向过程编程,函数式编程则完成一个功能,其他代码用来调用即可,提供了代码的重用性和代码间的耦合。而对于一个复杂的功能来,可能需要多个函数才能完成(函数又可以在不同的.py文件中),n个 .py 文件组成的代码集合就称为模块。
如:os 是系统相关的模块;file是文件操作相关的模块
模块分为三种:
- 自定义模块
- 第三方模块
- 内置模块
自定义模块
自定义模块很好理解了,就是自己写的模块,它可以是一个.py的文件,也可以是一个文件夹(如果是文件夹必须有__int__的目录才是模块,否则就是一个普通目录)
1.定义模块
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAO4AAACICAIAAABvIUAyAAAIQ0lEQVR4nO2dzW/bZBzH81+gHQdjRNpfENhAMME0NkCgIQ4ckCZhLlx2QdqEVtDY+zBc6AE29TCkql1tp3UStJCuEy1s63thWanblBXh9rChQUZBZlTh4Nax45f4cd2mv8ffj3Kon/h5ksOnj57Yz9e/VI0FSZIkSbp27dry8jJTx/72w/3th9nPKQiplFAw/9bETCqVETWz2fxjtdV2SkYQMmvv2UZpbPJpBHRJMZ2tqurS0lKEjzE1DfNq7FkQUqtkRNGyTxMza62CkLFUNk93GQqVkwCbypGJrjIjEDSxbJLKm4Qm2mdokCj4UdlciUDkxMKPyiDhQGXACVAZcAJUBpwAlQEnQGXACVAZcELL7vbNj/RuzkeDhNDKG9fMNuOuNPCH1B6MiCq7thjZtyjhP4MXGFTO5XKSF6qqNu3bIpXNDXSC4OhXEKwD+x5SQBwGlXVd91RZ1/WmfaPuV3YSdYHh3w9LFn5gW2AUi8UGj4vFYpiOlqZ3Fh+0ZUfbsqN3Fh/4neOkvhpwrAjqO5bNeVUTMzYrCw3zsI+wmJU5gk3larUqy7LlsSzL1Wo1TEdL07bs6JHOG0c6b7RlR/3OseFwzbbm1UTBtUiwCVsQHIZ6q+zInwDyMP/sGxoaslQeHBwM2cut8nElhMoNDjoPG+fl+tsNJnuobAtXAU5gVtkwDEVRzCnZMIyQ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KjPHVP13VAaojHgpXciozB5TNedXD2kDZ2X3IeKlNCCjctSYqjnXOtRlVBnxUhqQUZk5pqqJoi0q6lu9HfFSXiCjcoSYasE7KhqkMuKldCGj8sbHVBEvpQ0ZlTc+pop4KW1oqGwnXEw1AoiX0oaeygB4ApUBJ0BlwAlQGXACVAacAJUBJ0BlwAmbpHJ/++GG1/xI7+Z8NEgILVM5is24fQz8aaXKnq+gURhVtqVIIj+LFpCBQeVcLid5oapq074tUdkB9lHwDoPKuq57qqzretO+zTUNc846VEYChHvYFhjFYrHB42KxGKbjOlR2Pm7eXgEnfJ4Ui+wEwKZytVqVZdnyWJblajXUrrSoKlth0bUDq3KvsKZm8zwp1haJgPln39DQkKXy4OBgyF4RVQ6cXF3PBvDJk8LkZMCssmEYiqKYU7JhGCF7xayyJmacpdWtGnvuPCkWFwkhysW4iYkJSZKmpqbCd4ljgWHz16ZnszwpTE4KEa8rl0olpvOjX4yr/+rLiKJgn4pXWwXBPgk35kmxukgMpG6RhACTcGLhazsR5uAEw4/KyJMmHH5UBgkHKgNOgMqAE6Ay4ASoDDiBhsqopgqaQltlVFMFFpRUdjeimiqwoK0yqqkCC8Iqm6CaKjChpzKqqQJP6KmMaqrAEzIqo5oqCIaMyqimCoIhozKqqYJgyKiMaqogGDIqo5oqCIaMyqimCoIhozKqqYJgyKiMaqogGBoq20E1VeAJPZUB8AQqA06AyoAToDLgBKgMOIGGyoipgqbQVhkxVWBBSWV3I2KqwIK2yoipAgvCKpuwxVTtz9DHlgq+oKfyOmKqBcES2FFFDfAAPZXXH1Ot1WrY68YfZFSOMaZaq3nOyoip0oaMyjHGVJ0REWcrYqpkIaNyXDFVe/XKmusdxFTpQkblWGKqgT/2EFOlDRmVY4ipesqImCovkFE5hphq/djWjJgqL5BRGTFVEAwZlRFTBcHQUNkOYqrAE3oqA+AJVAacAJUBJ0BlwAlQGXDC/4qSA00d/r2XAAAAAElFTkSuQmCC" alt="" />
day12就是一个模块,因为存在__init__.py,day7就不是一个模块,因为没有__init__.py文件
一定有人会在心里问__init__.py里面是啥,为啥就这么吊,有它就是模块,没它就不是模块
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAAkEAAAB8CAIAAADhHfOgAAAbmElEQVR4nO2d+3MTR57A579I5Ufy9N7+QFFssas89iqb2qTy2gDxVXZJ7fHIomV346rjKuGOVAqZ5DAkZJXU3UVOYhyyBuLYHkuy9cD4BcKAkd+2ZAsL5IQE44vIxsY8gpaQuR9GGvXM9Mz0jKR5fj/VBdbMdE/PSNMffbtbMxQDAAAAANaEEmB0fQDADgivK7i4AKAcKFxXcJkBFiKBY1INlaub+FKCiwsASgdzZQlWA4BpwUqrFIcND8eHh+MVqq342gMAoHQUHDbG5x0JxtTR99GrGzfWtY211W3atOnVj/ryi9vqNuGoa1NZvNFkMpkjR458ASiRTCYbGxtTqVQ6nd69e/fu3bvT6XQqlWpsbEwmk+LtSaRVusPQlCxw4MCBYDD48M7mx3b76wM95/w/Od/5AJsuhB/MRKoykapU64okQqJn376mRDKZTCR6MFcaRXGbrV21dl9PIpHo2bd21aqaJnZ5/kUikd9mbU3N2rX7ehJJCdra2j766KMEu30i0dDQQNO01MYNDQ1Sq8pyvPvWrqppKla1qWbV2n09tj9e7n/BZrY93kRPT6HCTTWrkKPU73gNcFjvh69u3Pjqh72jvCV1bWNjY6Ntda9+2Cvevq5tdKwyjJQVVc3lNIL+8jAhrMPEyzV4q4wO40x24MCBrq6uF+vaH9nZcqSjfdZ/L3udZ8JVmXBVOnj/bOC+JP1zwQXWVLNq9erVq1evxjps9erVhYaveM3X1NSwWVbxW0OujZBvmwghaeNKOV6u5eKWSznMTsebaMofC4e931/2iPJLCpXX+XiVHVbeVt7eaHaYmDlgbq5Ee5XRYcPD8QMHDvT19fUejzUF+wb6D5+j78lEqs4ffSjZ+fS5ng0zZ96fOfvh9NQZFVdaIQ7jEIcvguaD00DpkLRxpRwvCXC8KHC82sBeWTyM9oKVKKPDnCmzskirQg7jUjweHz/9Wap1RSZ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MUPep9/NzI2nbx+ufvOP64KcrFhF0VRFOWOIsslHJb2uih3NOrm5Ul7XcjGYD9LAQ4DAKtjH4cdOnTopXeCj+w4/KtdrU++FXiqruO5/ZF17x975u3Q8FB7JlL11Ynf8PKwSsKVJuOwou2i7vzfyNZRt0SJgCkBhwGA1bGPw1paWh7d2fzrtwJP1nU8tS/09NvhZ96JPPtu9Nl9nenxhkyk6kLnA/xMbESFsZVsHCZ+yW0OCrMY4DAAsDr2cVgoFPrlG61P1HU+uTd0dCQxNHFiaOL40MTx6ZGDc5GfZiJVs4H7cFnZ6IrnLJUOY9Jel8ublo7rAJMCDgMAq2Mfhx0/fvzhnc2P7fb7z0ylgz893/kAmy6EH8xEqjKRqlTrCl6etNcbLfzFtw/PYcUBr7TXVexKFL5wud0uGAqzGOAwALA69nHY6OjoRm/kkZ0tffHTs/57WW9lwlWZcFU6eP9s4L5056OCXILpGehyKYe53fg88JsyKwIOAwCrYx+HpVKp2Qtz3WenL6T6ztH3ZCJVX/b+81xv9fzZPy592bp8KfxD7u+l7USusxAmJFoRcBgAWB37OOzixYsLCwvffvvtlYsnU60rMpGqica779y5M9F497WFnnLsRNphMBRmTcBhAGB1bOIwlDu3r80GHxn7+C42zfofunN7uRwF403FdkiCwawIOAwArI4NHQYAhIDDAMDqgMMA5wIOAwCrAw4DnAs4DACsDjgMcC7gMACwOuAwwLmAwwDA6oDDAOcCDgMAq1N0GIrRtQIAPai0w4TXFUVRFAUOA4ASwVxXgtX616nPt0WQ5oY79K8G4Ch0cJhgj+AwACgdzJUlv1oHxA7TojG44xOgBnAYAFgRyzgMm+RKUekw5DnO2Hv/AjYHHAYAVkR8Zf0/lFo9AAmASAIAAAAASUVORK5CYII=" alt="" />
最终结果却令人大失所望,__init__.py里面啥都木有,说白了就是一个空文件,但是你没有它就不行,就不是模块而是文件夹,如果你建了一个文件夹,又想变成模块,你自己在里面创建一个__init__.py就行了。
2.导入模块
Python之所以应用越来越广泛,在一定程度上也依赖于其为程序员提供了大量的模块以供使用,如果想要使用模块,则需要导入。导入模块有一下几种方法:
import module
from module.xx.xx import xx
from module.xx.xx import xx as rename
from module.xx.xx import *
导入模块其实就是告诉Python解释器去解释那个py文件
- 导入一个py文件,解释器解释该py文件
- 导入一个包,解释器解释该包下的 __init__.py 文件 【py2.7】
那么问题来了,导入模块时是根据那个路径作为基准来进行的呢?即:sys.path
import sys
print sys.path 结果:
['', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info']
如果sys.path路径列表没有你想要的路径,可以通过 sys.path.append('路径') 添加。
import sys
import os
project_path = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
sys.path.append(project_path)
内置模块
内置模块说白了就是python系统自带的一些常用模块,将一些常用的模块封装到了里面,在你使用的时候不用去安装,直接去引用就可以了。
1.sys模块
用于提供对Python解释器相关的操作:
sys.argv 命令行参数List,第一个元素是程序本身路径
sys.exit(n) 退出程序,正常退出时exit(0)
sys.version 获取Python解释程序的版本信息
sys.maxint 最大的Int值
sys.path 返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
sys.platform 返回操作系统平台名称
sys.stdin 输入相关
sys.stdout 输出相关
sys.stderror 错误相关
实例展示:
sys.argv #命令行参数List,第一个元素是程序本身路径
print sys.argv
python /root/test.py 123
返回结果:['/root/test.py', ''] sys.exit(n) #退出程序,正常退出时exit(0) sys.version #获取Python解释程序的版本信息
返回结果:
2.6.6 (r266:84292, Nov 22 2013, 12:16:22)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] sys.path #返回模块的搜索路径,初始化时使用PYTHONPATH环境变量的值
返回结果:
['', '/usr/lib64/python26.zip', '/usr/lib64/python2.6', '/usr/lib64/python2.6/plat-linux2', '/usr/lib64/python2.6/lib-tk', '/usr/lib64/python2.6/lib-old', '/usr/lib64/python2.6/lib-dynload', '/usr/lib64/python2.6/site-packages', '/usr/lib/python2.6/site-packages', '/usr/lib/python2.6/site-packages/setuptools-0.6c11-py2.6.egg-info'] sys.platform #返回操作系统名称
返回结果:
'linux2' sys.builtin_module_names #列表包含 Python 解释器中所有内建模块的名称
返回结果:
('__builtin__', '__main__', '_ast', '_codecs', '_sre', '_symtable', '_warnings', 'errno', 'exceptions', 'gc', 'imp', 'marshal', 'posix', 'pwd', 'signal', 'sys', 'thread', 'zipimport') sys.modules #字典包含所有加载的模块. import 语句在从磁盘导入内容之前会先检查这个字典.
返回结果:
{'abrt_exception_handler': <module 'abrt_exception_handler' from '/usr/lib64/python2.6/site-packages/abrt_exception_handler.pyc'>, 'os': <module 'os' from '/usr/lib64/python2.6/os.pyc'>}
标准输出和标准错误 (通常缩写为 stdout 和 stderr) 是内建在每一个 UNIX 系统中的管道。
当你 print 某些东西时,结果前往 stdout 管道;
当你的程序崩溃并打印出调试信息 (例如 Python 中的 traceback (错误跟踪)) 的时候,信息前往 stderr 管道
sys.stdout #输出相关
for i in range(3):
print'Dive in' Dive in
Dive in
Dive in
import sys
for i in range(3):
sys.stdout.write('Dive in') Dive inDive inDive in
for i in range(3):
sys.stderr.write('Dive in') Dive inDive inDive in
sys.stderror #错误相关
stdout 是一个类文件对象;调用它的 write 函数可以打印出你给定的任何字符串。
实际上,这就是 print 函数真正做的事情;它在你打印的字符串后面加上一个硬回车,然后调用 sys.stdout.write 函数。
在最简单的例子中,stdout 和 stderr 把它们的输出发送到相同的地方
和 stdout 一样,stderr 并不为你添加硬回车;如果需要,要自己加上。
stdout 和 stderr 都是类文件对象,但是它们都是只写的。
它们都没有 read 方法,只有 write 方法。然而,它们仍然是类文件对象,因此你可以将其它任何 (类) 文件对象赋值给它们来重定向其输出。
重定向展示
#!/usr/bin/env python
#-*-coding:utf-8-*- import sys print 'Dive in' # 标准输出,输出到终端上
saveout = sys.stdout # 终在重定向前保存stdout,这样的话之后你还可以将其设回正常
fsock = open('/root/out.log', 'w') # 打开一个新文件用于写入。如果文件不存在,将会被创建。如果文件存在,将被覆盖。
sys.stdout = fsock # 所有后续的输出都会被重定向到刚才打开的新文件上。 print 'This message will be logged instead of displayed' # 这样只会将输出结果“打印”到日志文件中;屏幕上不会看到输出 sys.stdout = saveout # 在我们将 stdout 搞乱之前,让我们把它设回原来的方式。
print 'dsadasdadadasdadasda' # 标准输出,输出到终端上
fsock.close() # 关闭日志文件。
结果展示:
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA4sAAADwCAIAAAAmfGarAAAgAElEQVR4nO2du47jONpAK5xwkokmmqSTygqoZIF9hK1kAKOiyTfoceTMD7CDAQzUAxhYdGjAL9CAYzvuuCK/xIb/H+jGy8eP1M2SqAOcoNu0JN5knfpIkU///e9///3vfz89v8IyePu43O+fp5354cvh9nm/H7dT52090ApzYPxWeDncPu+3/Vs+JYJceT/dP+/nd/U7j+7P1Ab0BENdGrvj3b73iqda7G4EWiE7Rm6F7fnzfr8cNvmUCPIl7mQT9GdqA/qBoS6Qzf56/7wb2EEXoBVWwyit8H4qzzZF5JJ+BV1QnGzS/kxtQA8wVAAAAACYFxgqAAAAAMwLDBUAAAAA5gWGCgAAAADzAkMFAAAAgHmBoQIAAADAvJAMtViTb35rnZRLA7q5ymLd3d1xHmuz1StxfA68CqPVqVjmAwAAADRChjqFLW321/vn9eNFTN2eDbPZ7K+NpK7QUIttZkbwyIbAenKb/bVqhe25y6WtdgQAAACQWIahvn1cXK3ZHSsrXZuhvhxuhhoW63sPL6kBQ3WqHUMFAACAEViEob6fhMkG76cyk2szVJdxdm+TDfXt42IaaijgHcsthgoAAAAa7Qy1EhRjlNlRQ326oZxqj1n78yCbuJ3Jy+FWaKtjqNXZzEPM6/qnCqa+nwpjNr5giLKe2rY2PMvU8+w0yvDThT1DdXP7mZg9h6Chmps9Lv3vDQAAAOhHe0M1VcyOetrBvMIU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Je0M1VcyOetrBvMIUm/Poqf7Zarbn6sNGki6HTf25Zajbs2eKu+NdmbSqpbpbbNtFEFMbDdXL62qlU+d6nr36eVgM1Zh7Kga2ZTBUAAAAaEUXQ5Xfoxf80rAcPbVANtTKhKq3o+o5qb6hCnoauEr1nYRUM/Zp5dBLNbUyUt4q/irXuZ4rm2Ieqh+glanD1dHvBw21zPZmf03WYgwVAAAAWtHBUGW5efu4eEc17qinlp+IhlqZkCmmtY+ahnoQ9NQJRhYYdqinCpbmWqY/Dl6cLVJe/7pmnUdy5Z0zOZbZNN/u2LSj3NyioRpzTzFUAAAAGI1hDdVNqm1STy0/CRrqcWu8OV4PNFuGKk7lfA3PnqxnuCqpgqWZL7BHDTVcXr+GPUMN58rOTHh9Lg/r7fu6Go2Xn0xihmo6bgwMFQAAAFqxiBhqaai1j9b/sN+U8obdX8V4ZHLquDHUiKFGw6LFlIY+60yVZ5Db2ild+G22hKxiqAAAANCKwQxVmitpjE3rqcYZAoZaf9n8h7falDApMzQ+npraYg6rNw81uTac96j0XD09D6GnMaQYqjGyH4i8ymCoAAAA0IrhDFV+e11/t905lfShPcpfvKpVrvEkrthfDJEb8qQvxqSmOpb2frp7b/qHDDVSXjPPL4fb5/V8NKd1puR5TD2VSvdqGWr6hlLPGCoAAAC0ZEhDfW4GjuUIn576/Pok7edZxUpr9Synadry5ymp/5Z90sqjdzeWaSZF1iLwRufV8jYnr1Yq6Jir4HqrvZAM1Zh7iqECAADAeMxpTymZFnsXDU1g589VMGTZMVQAAABoxfwNtd2Ux0HBUDFUAAAAmIAFGKo3AfTp7ePykKgqhoqhAgAAwASEDLXFWkIPwVntaNg5lyFWaKj2JFcMFQAAAKZAMlSAQcFQAQAAoBUYKgAAAADMCwwVAAAAAOYFhgoAAAAA8wJDBQAAAIB5gaECAAAAwLzAUAEAAABgVvw/z6LTKRjdNLcAAAAASUVORK5CYII=" alt="" />
这就是 print 函数真正做的事情;它在你打印的字符串后面加上一个硬回车,然后调用 sys.stdout.write 函数
sys.stdin实例:
import sys while True:
print '请输入两个数字,中间用空格隔开'
line = sys.stdin.readline()
if not line:
break
a = line.split()
print int(a[0]) + int(a[1])
关于raw_put()和readline()的区别:解析文章:http://www.cnblogs.com/dolphin0520/archive/2013/03/27/2985492.html
sys.stdin.readline( )会将标准输入全部获取,包括末尾的'\n',但是raw_input( )获取输入时返回的结果是不包含末尾的换行符'\n'的。
小实例:模拟进度条:
#!/usr/bin/env python
# _*_ coding:utf-8 _*_
import sys
for i in range(101):
#显示进度条百分比 #号从1开始 空格从99递减
hashes = '#' * int(i / 100.0 * 100)
sys.stdout.write("\r%s %s%%" % (hashes, i)) #必须两个%%才是,因为一个%是取模,python解释器会默认过滤
sys.stdout.flush() #强制刷新屏幕缓冲区使其一行输出
time.sleep(0.5)
2.os模块
用于提供系统级别的方案
os.getcwd() 获取当前工作目录,即当前python脚本工作的目录路径
os.chdir("dirname") 改变当前脚本工作目录;相当于shell下cd
os.curdir 返回当前目录: ('.')
os.pardir 获取当前目录的父目录字符串名:('..')
os.makedirs('dirname1/dirname2') 可生成多层递归目录
os.removedirs('dirname1') 若目录为空,则删除,并递归到上一级目录,如若也为空,则删除,依此类推
os.mkdir('dirname') 生成单级目录;相当于shell中mkdir dirname
os.rmdir('dirname') 删除单级空目录,若目录不为空则无法删除,报错;相当于shell中rmdir dirname
os.listdir('dirname') 列出指定目录下的所有文件和子目录,包括隐藏文件,并以列表方式打印
os.remove() 删除一个文件
os.rename("oldname","newname") 重命名文件/目录
os.stat('path/filename') 获取文件/目录信息
os.sep 输出操作系统特定的路径分隔符,win下为"\\",http://edu.51cto.com/index.php?do=lesson&id=103882Linux下为"/"
os.linesep 输出当前平台使用的行终止符,win下为"\t\n",Linux下为"\n"
os.pathsep 输出用于分割文件路径的字符串
os.name 输出字符串指示当前使用平台。win->'nt'; Linux->'posix'
os.system("bash command") 运行shell命令,直接显示
os.environ 获取系统环境变量
os.path.abspath(path) 返回path规范化的绝对路径
os.path.split(path) 将path分割成目录和文件名二元组返回
os.path.dirname(path) 返回path的目录。其实就是os.path.split(path)的第一个元素
os.path.basename(path) 返回path最后的文件名。如何path以/或\结尾,那么就会返回空值。即os.path.split(path)的第二个元素
os.path.exists(path) 如果path存在,返回True;如果path不存在,返回False
os.path.isabs(path) 如果path是绝对路径,返回True
os.path.isfile(path) 如果path是一个存在的文件,返回True。否则返回False
os.path.isdir(path) 如果path是一个存在的目录,则返回True。否则返回False
os.path.join(path1[, path2[, ...]]) 将多个路径组合后返回,第一个绝对路径之前的参数将被忽略
os.path.getatime(path) 返回path所指向的文件或者目录的最后存取时间
os.path.getmtime(path) 返回path所指向的文件或者目录的最后修改时间
3.hashlib
用于加密相关的操作,代替了md5模块和sha模块,主要提供 SHA1, SHA224, SHA256, SHA384, SHA512 ,MD5 算法
最常用的md5方法:
import hashlib hash = hashlib.md5() #以md5方式加密
hash.update('abcd') #更新哈希对象,以字符串
print hash.hexdigest()#返回十六进制数字字符串e2fc714c4727ee9395f324cd2e7f331f
print hash.digest() #返回摘要,作为二进制数据字符串值
查看支持的加密算法:
print hashlib.algorithms #列出所有加密算法
#('md5', 'sha1', 'sha224', 'sha256', 'sha384', 'sha512')
各种加密实例展示:
import hashlib # ######## md5 ########
hash = hashlib.md5() #以md5的方式加密
hash.update('admin')
print hash.hexdigest()
print hash.digest() ######## sha1 ######## hash = hashlib.sha1()#以sha1的方式加密
hash.update('admin')
print hash.hexdigest() # ######## sha256 ######## hash = hashlib.sha256() #以sha256的方式加密
hash.update('admin')
print hash.hexdigest() # ######## sha384 ######## hash = hashlib.sha384() #以sha384的方式加密
hash.update('admin')
print hash.hexdigest() # ######## sha512 ######## hash = hashlib.sha512() #以sha512的方式加密
hash.update('admin')
print hash.hexdigest()
这么多方式,能不能把加密方式当参数传入啊,python当然可以啦,人生苦短我用python啊!
new(name, string='') #用new 方法,name是指定的加密方式,string是加密的字符串,这地方可以和update一起用,组成加盐方式加密
"""
Return a new hashing object using the named algorithm;
optionally initialized with a string.
"""
import hashlib
#这两个方式其实是一样,但是用new方法更灵活,可以传如加密方式
h = hashlib.new('md5')
print h
h.update('beginman')
print h.hexdigest() #666fc5baa93a7fb207c5bfff03b67732 s = hashlib.md5()
s.update('beginman')
print s.hexdigest() #666fc5baa93a7fb207c5bfff03b67732
以上加密算法虽然依然非常厉害,但时候存在缺陷,即:通过撞库可以反解。所以,有必要对加密算法中添加自定义key再来做加密。
hash = hashlib.md5('wolegequ')#这个地方的是你自己在程序里面加的,不要轻易告诉别人,这样相当于自己又加了遇到防线。
hash.update('zhemediao')
print hash.hexdigest()
#d38300d8efb8f70d5828487ff7ca917
还有厉害的加密方法:python 还有一个 hmac 模块,它内部对我们创建 key 和 内容 再进行处理然后再加密。
import hmac
h = hmac.new('wolegequ')
h.update('zhemediao')
print h.hexdigest()
#31f4ff4c716b9bc8d12009fc336c5fd2
增量更新文件太大的时候,可以分多次读入:就是将加密的字符串割成小字符串。
import hashlib
hash = hashlib.md5('wolegequ')
hash.update('zhemediao')#可以切割成多个使用update方法
hash.update('bixude')#
print hash.hexdigest()
#6cf2ea119f173704dea8860281df3313 #这个方法和一次更新的结果一样
hash1 = hashlib.md5('wolegequ')
hash1.update('zhemediaobixude')#一整次更新
print hash1.hexdigest()
#6cf2ea119f173704dea8860281df3313
属性hashlib.algorithms包含支持的算法。
属性hash.digest_size :结果hash的大小
属性hash. block_size : hash内部块的大小
#!/usr/bin/env python
#-*- coding:utf-8 -*-
__author__ = 'wyf' import hashlib def md5(passwd):
hash = hashlib.md5('admin')
hash.update(passwd)
return hash.hexdigest() def registered (user,passwd):#注册用户函数
with open('db.conf','a') as f:
temp = user +'|'+ md5(passwd)
f.write(temp+'\n') def login(user,passwd):
with open('db.conf','r') as f1:
for i in f1:
u,p = i.strip().split('|')
if u == user and p == md5(passwd):
return True
def main():
print u'1、登录;2、注册;3.退出'
chooseNum = raw_input('请输入选择的操作》》》:')
if chooseNum == '':
user = raw_input('请输入用户名》》》:')
passwd = raw_input('请输入密码》》》:')
if login(user,passwd):
print '登录成功'
else:
print '登录失败' elif chooseNum =='':
user = raw_input('请输入用户名》》》:')
passwd = raw_input('请输入密码》》》:')
registered(user,passwd) if __name__ == '__main__':
main()
登录小练习
4.json和pickle
用于序列化的两个模块
- pickle,用户python特有的类型和python的数据类型间进行转换。
- json,用于字符串和python的数据类型间进行转换。
pickle模块:
pickle模块使用的数据格式是python专用的,并且不同版本不向后兼容,同时也不能被其他语言识别。要和其他语言交互,可以使用内置的json包,使用pickle模块你可以把python对象直接保存到文件,而不需要把他们转化为字符串,也不用底层的文件访问操作把它们写入到一个二进制文件里。 pickle模块会创建一个python语言专用的二进制格式,你基本上不用考虑任何文件细节,它会帮你干净利落地完成读写独享操作,唯一需要的只是一个合法的文件句柄。
pickle模块中的两个主要函数是dump()和load()。dump()函数接受一个文件句柄和一个数据对象作为参数,把数据对象以特定的格式保存到给定的文件中。当我们使用load()函数从文件中取出已保存的对象时,pickle知道如何恢复这些对象到它们本来的格式。
dumps()函数执行和dump() 函数相同的序列化。取代接受流对象并将序列化后的数据保存到磁盘文件,这个函数简单的返回序列化的数据。
loads()函数执行和load() 函数一样的反序列化。取代接受一个流对象并去文件读取序列化后的数据,它接受包含序列化后的数据的str对象, 直接返回的对象。
dumps和dump区别展示:
#!/usr/bin/env python
#-*- coding:utf-8 -*-
import pickle s = '{"desc":"ininia","status":200,"aaa":[11,22,33,44,55,66]}' f = open('abc.txt','r+')
a = pickle.dump(s,f) #dump除了传存储对象还有 打开的文件句柄
f.close() f1 = open('abc1.txt','r+')
a1 = pickle.dumps(s) # dumps 直接传存储对象
f.write(a1)
f.close()
loads和load是dumps和dump的反操作因此都一样。
json模块:
似乎pickle已经和吊了,能满足几乎所有的序列化和反序列话,但是不要忘记前面提到的pickle只是python特有的操作,只能python才能操作,如果这样的话是不是太局限了?这时候json就有存在的意义了,它可以跨语言进行数据交换,基本上大多数语言都支持json,如果是两个跨语言的数据交换,json是最好的选择,你只要说哥们json吧。但是有一点必须注意,json是很多语言都支持,这也导致了一些局限性,有些python支持的数据类型,json不支持,因此json序列化一般为字典和列表。
json的用法和pickle一样,提供了四个功能:dumps、dump、loads、load。
实例:
s = '{"desc":"ininia","status":200,"aaa":[11,22,33,44,55,66]}'
s1 = {"desc":"ininia","status":200,"aaa":[11,22,33,44,55,66]}
import json
result = json.loads(s)#将字符串转换成对象
print result,type(result)
#{u'status': 200, u'aaa': [11, 22, 33, 44, 55, 66], u'desc': u'ininia'} <type 'dict'> result1 = json.dumps(s1)#将对象转换成字符串
print result1,type(result1)
#{"status": 200, "aaa": [11, 22, 33, 44, 55, 66], "desc": "ininia"} <type 'str'>
python-模块系列的更多相关文章
- 扩展Python模块系列(一)----开发环境配置
本系列将介绍如何用C/C++扩展Python模块,使用C语言编写Python模块,添加到Python中作为一个built-in模块.Python与C之间的交互目前有几种方案: 1. 原生的Python ...
- 扩展Python模块系列(二)----一个简单的例子
本节使用一个简单的例子引出Python C/C++ API的详细使用方法.针对的是CPython的解释器. 目标:创建一个Python内建模块test,提供一个功能函数distance, 计算空间中两 ...
- 扩展Python模块系列(四)----引用计数问题的处理
承接上文,发现在使用Python C/C++ API扩展Python模块时,总要在各种各样的地方考虑到引用计数问题,稍不留神可能会导致扩展的模块存在内存泄漏.引用计数问题是C语言扩展Python模块最 ...
- 扩展Python模块系列(五)----异常和错误处理
在上一节中,讨论了在用C语言扩展Python模块时,应该如何处理无处不在的引用计数问题.重点关注的是在实现一个C Python的函数时,对于一个PyObject对象,何时调用Py_INCREF和Py_ ...
- 扩展Python模块系列(三)----参数解析与结果封装
在上一节中,通过一个简单的例子介绍了C语言扩展Python内建模块的整体流程,从本节开始讲开始深入讨论一些细节问题,在细节讨论中从始至终都会涉及[引用计数]的问题.首先讨论C语言封装的Python函数 ...
- 【听如子说】-python模块系列-AIS编解码Pyais
Pyais Module Introduce pyais一个简单实用的ais编解码模块 工作中需要和ais打交道,在摸鱼的过程中发现了一个牛逼的模块,对ais编解码感兴趣的可以拿项目学习一下,或者运用 ...
- python基础系列教程——Python3.x标准模块库目录
python基础系列教程——Python3.x标准模块库目录 文本 string:通用字符串操作 re:正则表达式操作 difflib:差异计算工具 textwrap:文本填充 unicodedata ...
- Python学习系列(六)(模块)
Python学习系列(六)(模块) Python学习系列(五)(文件操作及其字典) 一,模块的基本介绍 1,import引入其他标准模块 标准库:Python标准安装包里的模块. 引入模块的几种方式: ...
- $python正则表达式系列(2)——re模块常用函数
本文主要介绍正则re模块的常用函数. 1. 编译正则 import re p = re.compile(r'ab*') print '[Output]' print type(p) print p p ...
- Python模块学习系列
python模块-time python模块-datetime python模块-OS模块详解
随机推荐
- sqlmap的详细使用
各项参数讲的太仔细了,对于只会几个参数的我来说,太受用了. 先mark下 http://drops.wooyun.org/tips/143 http://drops.wooyun.org/tips/4 ...
- React 从0开始 消息传递
React笔记 React 数据决定DOM 以往的做法是通过JS去操作DOM 将数据填充 JSX Jsx javascript xml HTML的结构组装到js中 jsx使用style的时候 不能直接 ...
- 【Chromium中文文档】线程
线程 转载请注明出处:https://ahangchen.gitbooks.io/chromium_doc_zh/content/zh//General_Architecture/Threading. ...
- [Django 1.5] Windows + Apache + wsgi配置
基本步骤 下载安装Apache http://httpd.apache.org/download.cgi. 下载安装modwsgi 模块http://code.google.com/p/modwsgi ...
- 论山寨手机与Android 【14】3G SmartPhone时代的MTK
分析了SmartPhone的里里外外以后,现在我们可以分析MTK的机遇和挑战了.MTK面临的外部环境在发生变化,变化有两条,一是移动网络从2G演变到3G,二是手机由FeaturePhone演化到Sma ...
- 有趣的keil MDK细节
1.MDK中的char类型的取值范围是? 在MDK中,默认情况下,char 类型的数据项是无符号的,所以它的取值范围是0-255.它们可以显式地声明为signed char 或 unsigned.因此 ...
- MATLAB介绍
MATLAB MATLAB[1] 是美国MathWorks公司出品的商业数学软件,用于算法开发.数据可视化.数据分析以及数值计算的高级技术计算语言和交互式环境,主要包括MATLAB和Simulink ...
- 转载文章:Windows Azure 基础结构服务上的 Microsoft Dynamics NAV 和 Microsoft Dynamics GP!
Windows Azure 基础结构服务(虚拟机和虚拟网络)可提供按需基础结构,该基础结构可进行伸缩以适应不断变化的业务需求.无论您是在虚拟机中创建新应用程序,还是运行现有应用程序,我们都将按分钟收费 ...
- uva 10306 - e-Coins(完全背包)
题目链接:10306 - e-Coins 题目大意:给出m和s, 再给出m种电子硬币,每种硬币有两种金额xi,yi.现在要在m种硬币种选若干个硬币,可以重复选同一种硬币, 使得(x1 + x2 + . ...
- Java NIO——2 缓冲区
一.缓冲区基础 1.缓冲区并不是多线程安全的. 2.属性(容量.上界.位置.标记) capacity limit 第一个不能被读或写的元素 position 下一个要被读或写的元素索引 mark ...