生成多个文件脚本
#coding=utf-8
#import os
#import sys
sql1Script = '''
use scrm_%s;
-- 公司code需替换为相应公司的code
CREATE OR REPLACE VIEW `scrm_crm_contract` AS SELECT * FROM scrm_jishufuwu.`scrm_crm_contract` WHERE `company_code` = '%s';
-- 更新数据库版本.
INSERT INTO gf_db_version (MAIN_VERSION, DB_VERSION, SQL_NAME) VALUES ('R0028.000', 'R0028.000.000', 'R0028.000.000.0001.company.sql');
'''
def init_sql_execute():
db_name=["Hitech", "Ztltech", "Bslm", "Yn"]
# 替换字符串.
for item in db_name:
sql1 = sql1Script % (item, item)
script = sql1
# 生成脚本文件.
fp = open("saas_sql_"+item+".sh", "w")
fp.write(script)
fp.close()
if __name__ == "__main__":
init_sql_execute()
将多个文件输出到一个文件中
#!/usr/bin/python
#encoding:utf-8
import os
# 目标文件夹的路径
filedir = r'/data/test'
#获取目标文件的文件名称列表
filenames=os.listdir(filedir)
f=open(r'/data/test/aa.sh', 'w+')
for filename in filenames:
filepath = filedir + '/' + filename
for line in open(filepath):
f.writelines(line)
f.write('\n')
f.close()