上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 19 下一页
摘要: 1、函数对象 函数是第一类对象,可以当作数据进行传递 特性: 1)可以被引用 1 def func(): 2 print('from func') 3 4 f = func #把函数地址当作变量一样进行传递 5 f() 2)可以当作参数传递 1 def func(): 2 print('from f 阅读全文
posted @ 2017-05-29 00:58 SpeicalLife 阅读(213) 评论(0) 推荐(0)
摘要: 文件处理 1、读取文件 f = file('/etc/passwd','r') > Python 3.x 里面没有file,统一用open for line in f.readlines(): line = line.strip('\n').split(':') print line 结果: ['r 阅读全文
posted @ 2017-05-19 21:55 SpeicalLife 阅读(267) 评论(0) 推荐(0)
摘要: 1 #!/usr/bin/env python 2 # _*_ coding:UTF-8 _*_ 3 # __auth__: Dalhhin 4 # Python 3.5.2,Pycharm 2016.3.2 5 # 2017/05/15 6 7 import sys,os 8 9 def where(dbfile,where_list): #条件是一个... 阅读全文
posted @ 2017-05-19 21:43 SpeicalLife 阅读(534) 评论(0) 推荐(1)
摘要: #!/usr/bin/env python # _*_ coding:UTF-8 _*_ # __auth__:Dahlhin import sys userinfo = r'userinfo.txt' userlock = r'userlock.txt' def user_exist_check(user): '''检查用户是否存在''' with open(user... 阅读全文
posted @ 2017-05-10 19:40 SpeicalLife 阅读(351) 评论(0) 推荐(0)
摘要: 1、进制 每8位分为一组,8位成为一个字节 万国码定义字节是不固定的,最少两个字节 保存文件的时候要选择编码格式 unicode - utf-8 每个字符集,都有自己的编码格式(编码对应关系) utf-8 3个字节 gbk 2个字节 不能以utf-8存储,用gbk去读取,这样就会造成乱码 总结: 1 阅读全文
posted @ 2017-05-08 18:38 SpeicalLife 阅读(414) 评论(0) 推荐(0)
摘要: 1 #!/usr/bin/env python 2 # _*_ coding:UTF-8 _*_ 3 # 收集程序所占用的物理内存大小,占所有物理内存的比例 4 # OS: Centos 6.7 Python: 2.7.6 5 # __author__:Dahlhin 6 7 import sys 8 import os 9 from subprocess import ... 阅读全文
posted @ 2017-05-05 12:00 SpeicalLife 阅读(1343) 评论(0) 推荐(1)
摘要: 1 #!/usr/bin/env python 2 3 import os 4 import string 5 6 #方法1:通过字符串的isdigits来判断 7 #filelist = os.listdir('/proc') 8 # 9 #for pid in filelist: 10 # if pid.isdigit(): 11 # print p... 阅读全文
posted @ 2017-05-04 21:09 SpeicalLife 阅读(672) 评论(0) 推荐(0)
摘要: 1 #!/usr/bin/env python 2 #_*_ coding:utf-8 _*_ 3 #计算整个目录的大小,脚本接受-H参数,来加上适当的单位 4 #功能像du看齐 5 6 import os,sys 7 from optparse import OptionParser 8 9 10 def option(): 11 parser = Op... 阅读全文
posted @ 2017-05-03 15:42 SpeicalLife 阅读(452) 评论(0) 推荐(0)
摘要: 生成器是一个可迭代的对象,可以对可迭代的对象进行便利,比如字符串、列表等,都是可迭代对象 def f(n): for i in range(n): yield i 特点: 1、当调用这个函数的时候,函数内部的代码并不立马执行,这个函数只是返回一个生成器对象 2、当使用for进行迭代的时候,函数内的代 阅读全文
posted @ 2017-05-02 23:04 SpeicalLife 阅读(578) 评论(0) 推荐(0)
摘要: hashlib用于对字符串或者文件进行加密。 使用方法1: hashlib.md5('str').hexdigest() 使用MD5对str进行加密,使用hexdigest(),16进制的方式打印 使用方法2: md5 = hashlib.md5() md5.update('hello') 如果第一 阅读全文
posted @ 2017-05-01 23:57 SpeicalLife 阅读(1221) 评论(0) 推荐(0)
上一页 1 ··· 9 10 11 12 13 14 15 16 17 ··· 19 下一页