摘要:
执行格式: ./set_bridge.sh -i 192.168.4.72 -g 192.168.4.1 结果: [root@localhost ~]# ifconfigbr0: flags=4163<UP,BROADCAST,RUNNING,MULTICAST> mtu 1500 inet 192 阅读全文
摘要:
使用正则表达式收集主机信息 #!/usr/bin/env python from subprocess import Popen, PIPE import re def getIfconfig(): p = Popen(['ifconfig'], stdout=PIPE) data = p.stdo 阅读全文
摘要:
#!/usr/bin/env python from subprocess import Popen, PIPE def getIfconfig(): p = Popen(['ifconfig'], stdout=PIPE) data = p.stdout.read() return data de 阅读全文
摘要:
#!/usr/bin/env python from subprocess import Popen, PIPE def getIfconfig(): p = Popen(['ifconfig'], stdout=PIPE) data = p.stdout.read().split('\n\n') 阅读全文
摘要:
#!/usr/bin/env python from subprocess import Popen, PIPE p = Popen(['dmidecode'], stdout=PIPE) data = p.stdout lines = [] dmi = {} a = True while a: l 阅读全文
摘要:
按字典值排序 按照字典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_ 阅读全文
摘要:
#!/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 阅读全文
摘要:
#!/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 阅读全文
摘要:
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__ == '__ 阅读全文
摘要:
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 阅读全文