#!/usr/bin/env python #-*- coding:utf-8 -*- ''' 统计系统内存信息 ''' with open('/proc/meminfo') as fd: for line in fd: if line.startswith('MemTotal'): MemTotal = line.split()[1] continue if line.startswith('MemFree'): MemFree = line.split()[1] break print "总
#!/usr/bin/env python import os,sys list = [] for i in range(3,50): l = os.popen("/bin/echo 'show collections'| /usr/local/mongodb/mongodb/bin/mongo 127.0.0.1:27103/数据库名|sed -n '%sp'" %i) #获取数据库的集合列表 l = l.read() if l != "": list.appen
1.python 利用字典作为计数项,统计指定项的个数 #!/usr/bin/python ta={} key = "test" if not key in ta: ta["test"]=0 for i in range(1,5): ta["test"] += 1 print ta 2.dictionary(或是列list)在python中循环方式为直接利用该对象: next={"1":"a"
python连接oracle -- qlalchemy import cx_Oracle as co import pandas as pd from sqlalchemy import create_engine sql_select = ''' ...''' db = create_engine('oracle://qmcb:qmcb@localhost:1521/tqmcbdb') #test_data = pd.read_excel("data/tmp001.xlsx")
01 Python增加元素,不像其他语言使用现实的操作接口,只需要dict[1]=3,如果字典中不存在1,则直接新增元素键值对(1,3),如果存在则替换键1为3. if key in dict:判断出key是否在dict字典中. 统计元素出现的次数: def word_count(nums): dict={} for it in nums: if it not in dict: dict[it] = 1 else: dict[it] += 1 return dict print(word_cou