So cute are you python 17
2013-11-16 21:13
239 查看
1.python 实现linux ls 命令:
2.python 实现文件的遍历1:
3.python 实现文件的遍历2:
4.python cmd 的使用:
效果图:
#!/bin/evn python #coding:utf-8 #FileName:ls.py #Function:Show the files or directories on a path. #history:16-11-2013 import os path=raw_input("Pleace input the path you want to check._") print os.listdir(path)
2.python 实现文件的遍历1:
#!/bin/evn python #FileName:walk.py #Function:Show the files or directories on a path. #history:16-11-2013 import os export =[] path=raw_input('Pleace input the path you wanna to check._') for root,dirs,files in os.walk(path): export.append("\n%s; %s; %s"%(root,dirs,files)) open('myc.txt','w').write(''.join(export))
3.python 实现文件的遍历2:
#!/bin/evn python #FileName:walk_1.py #Function:Show the files or directories on a path. #history:16-11-2013 import os,sys def cdfiles(cdpath,cdfiles): export =[] if(len(cdpath)== 0): cdpath=raw_input('Pleace input the path you wanna to check._') for root,dirs,files in os.walk(cdpath): export.append("\n%s; %s; %s"%(root,dirs,files)) open('myc.txt','w').write(''.join(export)) if __name__=='__main__': #print sys.argv if(sys.argv[ 1]=='-e'): files='myc.txt' cdfiles(sys.argv[ 1],files) else: print '''Usage:_walk_1.py: python walk_1.py -e /var/ -- store the information into myc.txt.'''
4.python cmd 的使用:
#!/bin/evn python #coding:utf-8 #FileName:refactoring.py #Function:Show how to refactoring code. #history:16-11-2013 import sys,cmd,os class PyCDC(cmd.Cmd): def __init__(self,): cmd.Cmd.__init__(self) def cd_ls(self,filename,path): export =[] if path=="":path=raw_input('请输入搜索的路径_') for root,dirs,files in os.walk(path): export.append("\n%s; %s; %s"%(root,dirs,files)) open(filename,'w').write(''.join(export)) def help_EOF(self): print "退出程序" def do_EOF(self,line): sys.exit() def help_Walk(self): print '扫描文件内容 写入 *.txt' def do_walk(self,filename): spath="" if filename=="": filename=raw_input("输入导出文件的*.txt 文件名::") if spath=="": spath=raw_input("请输入要搜索的路径::") export =[] for root,dirs,files in os.walk(spath): export.append("\n%s; %s; %s"%(root,dirs,files)) open(filename,'w').write(''.join(export)) print '扫描的内容 存放于 %s'%filename def help_dir(self): print '指定保存路径.' def do_dir(self,path): if path=="":path=raw_input("Pleace input the path you wanna to search.") print "" def help_find(self): print "搜索关键字." def do_find(self,keyword): if keyword=="":keyword=raw_input("输入搜索关键字:_") print "搜索关键字 %s"%keyword if __name__=='__main__': cdc=PyCDC() cdc.cmdloop()
效果图:
$ python refactoring.py (Cmd) walk 输入导出文件的*.txt 文件名::myc.txt 请输入要搜索的路径::/var/www/sql 扫描的内容 存放于 myc.txt (Cmd) help Documented commands (type help <topic>): ======================================== EOF dir find Miscellaneous help topics: ========================== Walk Undocumented commands: ====================== help walk (Cmd) EOF
相关文章推荐
- So cute are you python 1
- So cute are you python 15
- So cute are you python 3
- So cute are you python 2
- So cute are you python 4
- So cute are you Python 13
- So cute are you python 7
- So cute are you python 16
- So cute are you python 5
- So cute are you Python 9
- so cute are you python 18
- So cute are you Python 12
- So cute are you Python 11
- So cute are you Python 10
- So cute are you python 6
- So cute are you python 14
- Windows下使用BeautifulSoup 出现You are trying to run the Python 2 version of Beautiful Soup under Python
- This application has no explicit mapping for /error, so you are seeing this as a fallback.
- time and again-------You are so considerate.
- Whitelabel Error Page This application has no explicit mapping for /error, so you are seeing this a