试图在Python中删除联合ASCII文件之间的标头
我是 python 的新手,我被要求合并一批 ascii 文件。每个文件都是由用户上传的,它们的顶部和底部都有一个标题。输出(组合)文件只需在顶部和底部有一个标头(组合文件之间的所有标头都需要删除)。
在下面的代码中,您将看到我设法将它们组合在一起,但我无法弄清楚如何删除组合文件之间的标头。
import tkinter as tk
from tkinter import filedialog
ASCII_Data_Files = filedialog.askopenfilenames(filetypes = [('ASC Files', '*.asc'),('All Files', '*.*')])
Recombined_File = r"D:\\desktop\\try_data\\wip\\Recombined_File.asc"
with open(Recombined_File, 'w') as Output_file:
Header = False
for i in range(len(ASCII_Data_Files)):
Single_ASCII = ASCII_Data_Files[i] #single ASCII is a single element or single file in the selected files
with open (Single_ASCII, 'r') as ASCII_file:
Lines = ASCII_file.readlines()
for ASCII_line in Lines:
if Header == False:
Output_file.write(ASCII_line)
Header == False
Header == True
I am a compelete newbie to python and i was asked to combine a batch of ascii files. Each of these files are uploaded by the user and they all have a header at the top and bottom. The output (combined) file needs to have just a header at the top and bottom (all headers between the combined files need to be removed).
in my code below you will see that I managed to combine them together but I cannot figure out how to remove the headers in betwee the combined files.
import tkinter as tk
from tkinter import filedialog
ASCII_Data_Files = filedialog.askopenfilenames(filetypes = [('ASC Files', '*.asc'),('All Files', '*.*')])
Recombined_File = r"D:\\desktop\\try_data\\wip\\Recombined_File.asc"
with open(Recombined_File, 'w') as Output_file:
Header = False
for i in range(len(ASCII_Data_Files)):
Single_ASCII = ASCII_Data_Files[i] #single ASCII is a single element or single file in the selected files
with open (Single_ASCII, 'r') as ASCII_file:
Lines = ASCII_file.readlines()
for ASCII_line in Lines:
if Header == False:
Output_file.write(ASCII_line)
Header == False
Header == True
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论