python修改源码库代码_用python自动修改项目数据库连接

#coding=utf-8

import os

def WalkDir(dirname, *ext):# 遍历dirname目录及其子目录

for root,dirs,files in os.walk(dirname):

# root 是当前目录名

# dirs 是当前目录的子目录列表

# files 是当前目录的文件列表

# print (root)

for fname in files:

#if os.path.splitext(fname)[1] in list(*ext): # 判断扩展名是否在列表

if fname in list(*ext): # 判断扩展名是否在列表

print (root + "\\" + fname)

cont = ""

f = open(root + "\\" + fname, 'rt')

while True:

s = f.read()

if s=="":

break

else:

#s.replace("10.20.60.59:1521:dgcms20100201", "127.0.0.1:1521:orcl")

if s.find("10.20.60.59:1521:dgcms20100201") > -1:

s = s.replace("10.20.60.59:1521:dgcms20100201", "127.0.0.1:1521:orcl")

else:

#s = s.replace("127.0.0.1:1521:orcl", "10.20.60.59:1521:dgcms20100201")

s = s.replace("10.20.60.59:1521:dgcms20100201", "127.0.0.1:1521:orcl")

cont +=s;

f.close()

#print (cont)

#修改配置文件后,写回到文件中

file_object = open(root + "\\" + fname, 'wt')

file_object.write(cont)

file_object.close()

if '__main__' == __name__:

WalkDir("E:\ALL_Work\DG_Project", ['jdbc.properties', 'hibernate.cfg.xml'])

分享到:

sina.jpg

tec.jpg

2011-08-30 18:32

浏览 823

评论

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值