my first python
2014-09-23 18:01
148 查看
#!/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)
# -*- 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)
相关文章推荐
- My first Python Program -- Command line Address Book
- My first python program -- get english and chinese from .ass file
- My first Python
- C++ Boost 之Python(生成一个扩展模块)
- Python指南--数据结构
- Python指南--数据结构
- 搭建Python的集成开发环境WingIDE
- Python指南--深入流程控制
- Python指南--深入流程控制
- 用Python实现数据库编程
- Python指南--开胃菜
- Python指南--开胃菜
- Python指南--初步认识Python
- Python指南--前言
- Python指南--使用Python解释器
- Python指南--使用Python解释器
- python库lxml在linux和WIN系统下的安装
- C++ Boost 之Python(一个简单的例子)
- C++ Boost 之Python(继承)
- C++ Boost 之Python(大纲)