zoukankan      html  css  js  c++  java
  • my first python

    #!/usr/bin/python
    # -*- coding:utf8 -*-

    import os
    import re

    def swap(path, a, b):
        print path
        file = open(path, "r").read()
        file = re.sub(a,b,file)
        #print file
        fw = open(path, 'wb')
        fw.write(file)
        #print fw.name()
        fw.close()

    def getlist(path, src, dest):
        if( not os.path.isdir(path)):
            #print 'it is not dir'
            a,b = os.path.splitext(path)
            if b == ".as":
                swap(path, src, dest)
        else:
            path = path.replace("/", "\")
            if path[-1] != "\":
                path = path + "\"
            a = os.listdir(path)
            for x in a :
                if os.path.isdir(path + x) and x != "CVS":
                    getlist(path + x, src, dest)
                if os.path.isfile(path + x):
                    a,b = os.path.splitext(path+x)
                    if b == ".as":
                        swap(path+x, src, dest)

    if __name__ == "__main__":
        import sys
        if len(sys.argv) == 1:
            print "nedd argv"
            exit()
        for i in sys.argv:
            if os.path.exists(i) and i != 'test01.py':
                print("please input: if a replaced with b  input a b")
                a=raw_input()
                print "your input is %s ." % a
                a,b = a.split()
                getlist(i, a,b)

  • 相关阅读:
    线程的中断
    线程间的协作机制
    iOS app内打开safari完成google的OAuth2认证
    iOS ipa 重签名 resign
    iOS rebuild from bitcode对ipa大小的影响
    iOS URL Cache文章推荐 (待完成)
    iOS 推荐几篇关于Objective-c 动态语言的文章
    iOS Code Sign On Copy
    设计模式好文章汇总(不断更新中)
    Json 文件中value的基本类型
  • 原文地址:https://www.cnblogs.com/xhmf/p/3989000.html
Copyright © 2011-2022 走看看