共计 2329 个字符,预计需要花费 6 分钟才能阅读完成。
这篇文章主要讲解了“python 怎么读文件”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着丸趣 TV 小编的思路慢慢深入,一起来研究和学习“python 怎么读文件”吧!
#!usr/bin/env python
# encoding:utf-8
def readfile(filename):
lines = [line for line in open(filename)]
def printTimeTaken(filename):
filename= data/aaa.csv
lines = [line for line in open(filename)]
for line in lines[: ]:
if not line.__contains__(Time taken: 0.):
print(line.replace( \n , ))
def appendToFile(context,filepath):
print()
def contactexp(tb,date_list,cpexp,file,filesql):
for tbname in tb:
if tbname.replace(\n ,).endswith(day) or tbname.replace(\n ,).endswith(semester)or tbname.replace(\n ,).endswith(7days):
for date_item in date_list:
file.write(cpexp.format_map(vars()).lower() + \n)
filesql.write(addPart.format_map(vars()).lower()+ \n)
else:
date_item= 2020-08-01
file.write(cpexp.format_map(vars()).lower() + \n)
filesql.write(addPart.format_map(vars()).lower()+ \n)
def whh(filename,file,filesql):
with open(file, w+) as file:
with open(filesql, w+) as filesql:
tbname_list=[]
lines = [line for line in open(filename)]
for line in lines[: ]:
if line.lower().replace( \n ,).endswith(_):
tbname_list=[line.lower().replace(\n ,)+ day ,line.lower().replace( \n ,)+ week ,line.lower().replace( \n ,)+ semester ,line.lower().replace( \n ,)+ 7days ]
# tbname_list = [line.lower().replace(\n , ) + week ]
contactexp(tbname_list, date_list, cpexp, file,filesql)
else:
#for date_item in date_list:
date_item = 2020-08-01
tbname=line.lower().replace( \n ,)
file.write(cpexp.format_map(vars()).lower() + \n)
filesql.write(addPart.format_map(vars()).lower() + \n)
#date_list=[2020-06-15 , 2020-06-16 , 2020-06-17 , 2020-06-18 , 2020-06-19 , 2020-06-20 , 2020-06-21]
date_list=[2020-08-01]
cpexp= hadoop fs -rm -r /user/hive/warehouse/dev_treasury.db/{tbname}/day={date_item} \n hadoop distcp hdfs://10.1.11.3:8020/user/hive/warehouse/treasury.db/{tbname}/day={date_item} hdfs://sandbox-hadoop-03.xuele.net:8020/user/hive/warehouse/dev_treasury.db/{tbname}/day={date_item}
addPart= alter table {tbname} add partition (day= {date_item}
#fileC= open(data/shell , w)
file= data/shell
filesql= data/sql
#date_list.append()
print(test)
#for date_item in date_list:
# print(date_item.replace( \n ,))
tbname_list=whh(data/replyjob ,file,filesql)
#contactexp(tbname_list,date_list,cpexp,file)
感谢各位的阅读,以上就是“python 怎么读文件”的内容了,经过本文的学习后,相信大家对 python 怎么读文件这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是丸趣 TV,丸趣 TV 小编将为大家推送更多相关知识点的文章,欢迎关注!
正文完