import sys
sys.path.append("包的绝对路径")
import logout #导入模块
print logout.logout()
- 内置模块(os,sys,time)
- 自定义模块
- 第三方模块 #开源
微信男女统计:
import itchat
itchat.login()
# itchat.send("hello","filehelper")
itchat.auto_login(hotReload=True)
friends=itchat.get_friends(update=True) #列表
print friends
male=female=other=0
for i in friends[1:]:
sex=i["Sex"]
if sex==1:
male+=1
elif sex==2:
female+=1
else:
other+=1
print "男:%d"%male
print "女:%d"%female
print "其他:%d"%other
print len(friends)
os,sys,time,datetime,json/pickle,shutil,random
例:统计/var/log下以.log结尾的文件。
import os
filename=raw_input("please input filename:")
f=open(filename,"w+")
for file in os.listdir("/var/log/"):
if file.endswith(".log"):
f.write(file+"\n")
f.seek(0,0)
print f.read()
f.close()