zoukankan      html  css  js  c++  java
  • 学习python

    获取当前目录下的路径,目录和文件并写入文本

    1 # -*- coding:utf-8 -*-
    2 import os
    3 for root,dirs,files in os.walk(os.getcwd()):
    4  print root,dirs,files 
    5  open('mycd.cdc','a').write("%s %s %s" %(root,dirs,files))

    函数化,将同一个目录下的内容写入不同的文件中

    # -*- coding:utf-8 -*-
    import os
    def cdWalker(cdrom,cdcfile):
       export=""
       for root,dirs,files in os.walk(os.getcwd()):
          export+="
     %s;%s;%s" % (root,dirs,files)
       open(cdcfile,'w').write(export)
    cdWalker(os.getcwd,'cd1.cdc')
    cdWalker(os.getcwd,'cd2.cdc')

    模拟cmd命令

    # -*- coding:utf-8 -*-
    import sys,cmd
    class PyCDC(cmd.Cmd):
       def __init__(self):
           cmd.Cmd.__init__(self)
       def help_EOF(self):
           print "退出程序"
       def do_EOF(self,line):
           sys.exit()
    
       def help_walk(self):
           print "扫描光盘内容 walk cd and export into *.cdc"
       def do_walk(self,filename):
           if filename== "":filename = raw_input("输入cdc文件名::")
           print "扫描目录下的内容保存到:'%s'" % filename
    
       def help_dir(self):
            print "指定保存/搜索目录"
       def do_dir(self,pathname):
           if pathname=="": pathname = raw_input("输入指定保存/搜索目录:")
    
       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()

     安装character encoding auto-detection

    先装sudo apt-get install python-setuptools,然后进行安装sudo python setup.py install


    4,安装karrigell

    之前配置文件没有改,一直都不成功,后来在这里看到教程,成功了blog.sina.com.cn/s/blog_4dda073c0100q525.html(转)

  • 相关阅读:
    通过Xshell连接CentOS虚拟机
    Linux学习笔记
    JAVA学习摘要
    4k 对齐,你准备好了吗?
    图片种子制作方法,利用图片上传附件
    利用京东服务免费打造属于自己的网站
    PE制作实录 —— 补充说明
    PE制作实录 —— 定义我的 PE 工具箱
    浏览器 — 各项基准测试
    Windows 8.1 归档 —— Step 3 软件的选择与安装
  • 原文地址:https://www.cnblogs.com/newworldcom/p/4035157.html
Copyright © 2011-2022 走看看