python怎么读文件
这篇文章主要讲解了“python怎么读文件”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“python怎么读文件”吧!
成都创新互联-专业网站定制、快速模板网站建设、高性价比张店网站开发、企业建站全套包干低至880元,成熟完善的模板库,直接使用。一站式张店网站制作公司更省心,省钱,快速模板网站建设找我们,业务覆盖张店地区。费用合理售后完善,10多年实体公司更值得信赖。
#!usr/bin/env python # encoding:utf-8 ###删除包含关键字“ Time taken: 0.” 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怎么读文件这一问题有了更深刻的体会,具体使用情况还需要大家实践验证。这里是创新互联,小编将为大家推送更多相关知识点的文章,欢迎关注!
当前名称:python怎么读文件
文章源于:http://ybzwz.com/article/ihghhj.html