0

I would like to merge a few dat files in a directory and exclude certain dat files as previously I have already marked out the files that I need and do not need. Below is an example of my codes

def onAssemble(self,event): 
    with open("index.dat", 'r') as file: 
        data = file.readlines() 
        print data 
        i = 1 
        fn = "python.dat" 
        f = open(fn) 
        output = [] 
        for line in data: 
            if not "*" in line: 
                output.append(line) 
        f.close() 
        t = open(fn, 'w')
        t.writelines(output) 
        t.close()

Edited by pyTony: messed up code formatting tried to fix

3
Contributors
4
Replies
23
Views
5 Years
Discussion Span
Last Post by pythonforlife
0

Python is indention sensitive, I tried to fix your code. Did I guess it right.

So what is your question?

0

Yes thank you very much. Sorry for the indention part. My questions is how do you search through a folder and only append certain dat files together and exclude the rest. For example there are 7 .dat files and I only want to append 4 of it together and not all.

0

Don't use file as a variable name since file() is function in python2
You don't do anything with f

Edited by HiHe

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.