October 11th, 2012, 02:44 PM
Help combining files
I am trying to take all the files in my folder proteinsequences and combine them all into one file. I have been on the nternet trying to find other peoples programs. This one seems like it should work but I get a syntax error. The arrow points to the =. in "print(l, file = out)" Any suggestions?
#set to the file extension of "to-be-merged" files
#set to your working directory
#set to the name of your output file
for f in files:
data = open(f)
out = open(results, 'w')
for l in data:
print(l, file = out)
October 11th, 2012, 03:15 PM
the code you posted is a python3 code. It won't work in python2.
Hmm, it has recently been shown to me that you might be able to import print_function from the future.
from __future__ import print_function
But why are you writing a program?
in unix, and it looks like you've got a unixy system, the command is:
$ cat *._ALL > NB_protein.fasta
I'm not going to bother checking what the DOS command is, but it's probably
A:> copy *._ALL NB_protein.fasta
[insert new floppy for A:]
[/code] are essential for python code and Makefiles!
October 11th, 2012, 03:51 PM
b49P23TIvg is right, no point writing a program that is already done by dos or terminal
but to answer your question your problem is you print(l, file = out), this doesn't work this way at least not to my knowledge use something like the following
That should be good enough to give you an idea of what you need to do. hope this has helped good luck with python
file = open('INFORMATION.txt', 'w')
a_file = open('MORE_INFORMATION.txt', 'w')
results = open('RESULTS.txt', 'w')
results.writeline("%s\n" % for item in file)
results.writeline("%s\n" % for item in a_file)
October 11th, 2012, 08:20 PM
Thank you for the help guys.
You were right I just used the cat *>file command in the terminal. The only reason I was trying to code it is because I didn't know it was so easily done.
Thank you again for the help!
October 12th, 2012, 11:05 AM