python如何另存文件,使用python添加到另一个文件以及如何保存两个文件

输入1:create external table db.emp(id int,name string)

row formatted fields terminated by ','

location 'hadfs:.../';

create external table db.emp1(id int,name string)

row formatted fields terminated by ','

location 'hadfs:.../';

输入2:create table db.emp(id int,name string)

location 'hadfs:.../';;

create table db.emp1(id int,name string)

location 'hadfs:.../';

再查询输出:create external table db.emp(id int,name string)

row formatted fields terminated by ','

location 'hadfs:.../';

create table db.emp(id int,name string)

location 'hadfs:.../';

这两个文件存储在file1.hql下create external table db.emp1(id int,name string)

row formatted fields terminated by ','

location 'hadfs:.../';

create table db.emp1(id int,name string)

location 'hadfs:.../';

这两个文件存储在file2.hql下,以此类推filenames = ['in1.txt', 'in2.txt']

with open('result.txt', 'w') as outfile:

for fname in filenames:

with open(fname) as infile:

content = infile.read().replace('\n', '')

outfile.write(content)

但是我没有得到正确的输出。请给我一个提示如何做到这一点。

使用此代码时,我得到的输出不正确

我试过密码import re

import sys

f = open ('text.txt','r')

fout = open ('hql.txt','w')

text = f.read()

fout = "hql.txt"

fout = open('hql.txt','w')

for item in re.findall(r'CREATE[^;]*;',text):

print >>fout, re.search(r'(?<=\.)\w+',item).group()+'.hql'

print >>fout,(item)

f.close()

fout.close()

此代码的o/p为:emp.hql

create external table db.emp(id int,name string)

row formatted fields terminated by ','

location 'hadfs:.../';

emp1.hql

create external table db.emp(id int,name string)

row formatted fields terminated by ','

location 'hadfs:.../';

它将向input1和input2文件生成这种输出。

现在我需要继续create external table db.emp(id int,name string)

row formatted fields terminated by ','

location 'hadfs:.../';

create table db.emp(id int,name string)

location 'hadfs:.../';

并以电磁脉冲hql等等。你知道吗

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值