上一页 1 ··· 84 85 86 87 88 89 90 91 92 ··· 102 下一页
摘要: #!/usr/bin/env python from subprocess import Popen, PIPE p = Popen(['dmidecode'], stdout=PIPE) data = p.stdout lines = [] dmi = {} a = True while a: l 阅读全文
posted @ 2017-09-14 15:46 Oops!# 阅读(439) 评论(0) 推荐(0)
摘要: 按字典值排序 按照字典value排序,类似sort -k 命令 import operator x= {1:2,3:4,4:3,2:1,0:0} sorted_x = sorted(x.iteritems(), key=operator.itemgetter(1)) In [38]: sorted_ 阅读全文
posted @ 2017-09-14 14:40 Oops!# 阅读(193) 评论(0) 推荐(0)
摘要: #!/usr/bin/env python import sys import hashlib def md5sum(f): m = hashlib.md5() with open(f) as fd: while True: data = fd.read(4096) if data: m.updat 阅读全文
posted @ 2017-09-14 14:17 Oops!# 阅读(180) 评论(0) 推荐(0)
摘要: #!/usr/bin/python import sys import os try: fn = sys.argv[1] except IndexError: print "please follow a argument at %s" % __file__ sys.exit() if not os 阅读全文
posted @ 2017-09-14 11:48 Oops!# 阅读(572) 评论(0) 推荐(0)
摘要: vim wc.py #!/usr/bin/python def wordCount(s): chars = len(s) words = len(s.split()) lines = s.count('\n') print lines, words, chars if __name__ == '__ 阅读全文
posted @ 2017-09-14 11:11 Oops!# 阅读(255) 评论(0) 推荐(0)
摘要: Python 函数 lambda 匿名函数 -lambda 函数是一种快速定义单行的最小函数,可以用在任何需要函数的地方。 def fun(x,y): return x*y fun(2,3) r=lambda x,y:x*y r(2,3) In [10]: def fun(x,y): ....: r 阅读全文
posted @ 2017-09-14 09:51 Oops!# 阅读(219) 评论(0) 推荐(0)
摘要: #!/usr/bin/python import os import sys def print_files(path): lsdir = os.listdir(path) dirs = [i for i in lsdir if os.path.isdir(os.path.join(path,i)) 阅读全文
posted @ 2017-09-14 09:40 Oops!# 阅读(376) 评论(0) 推荐(0)
摘要: 计算阶层 普通方法: -使用循环 #!/usr/bin/python def factorial(n): sum = 1 for i in range(1,n+1): sum *= i return sum print factorial(5) 计算阶层 python 7.py 120 #!/usr 阅读全文
posted @ 2017-09-14 09:22 Oops!# 阅读(257) 评论(0) 推荐(0)
摘要: #!/usr/bin/python import sys def isNum(s): for i in s: if i in '0123456789': pass else: print "%s is not a number" %s sys.exit() else: print "%s is a 阅读全文
posted @ 2017-09-13 17:54 Oops!# 阅读(204) 评论(0) 推荐(0)
摘要: 猜数字游戏 系统生成一个100以内的随机整数, 玩家有6次机会进行猜猜看,每次猜测都有反馈(猜大了,猜小了,猜对了-结束) 6次中,猜对了,玩家赢了。 否则系统赢了 #!/usr/bin/env python import random secret=random.randint(1,100) gu 阅读全文
posted @ 2017-09-13 16:45 Oops!# 阅读(265) 评论(0) 推荐(0)
上一页 1 ··· 84 85 86 87 88 89 90 91 92 ··· 102 下一页