试图在Python中删除联合ASCII文件之间的标头

发布于 2025-01-20 14:45:53 字数 1016 浏览 2 评论 0原文

我是 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文