Get the App
SLTechnology News&Howtos  ›  Servers  › 

How does python read the file?

Shulou Source: shulou.com Published: 2022-05-31 23:22:49 09月30日 Update

This article mainly explains "python how to read the file", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "python how to read the file" bar!

#! usr/bin/env python# encoding:utf-8### delete contains the keywords "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 ("day") or tbname.replace ("day"). 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 ('\ njinzhuo') + "day", line.lower (). Replace ('\ njinzhuo') + "week", line.lower (). Replace ('\ njingjue') + "semester", line.lower (). Replace ('\ n') '') + "7days"] # tbname_list = [line.lower (). Replace ('\ nails,'') + "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 ('\ nzhongjia')) tbname_list=whh (" data/replyjob ", file,filesql) # contactexp (tbname_list,date_list,cpexp,file) Thank you for your reading. That's how python reads the file. After the study of this article, I believe you have a deeper understanding of how to read the file of python, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Documents learning content keys keywords that is ideas situations articles more knowledge knowledge points articles follow questions practice push research verification Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Docker MySQL Xiaomi Shulou Tech Info OPPO Reno