I am currently reproducing the following Unix command:
cat command.info fort.13 > command.fort.13
in Python with the following:
with open('command.fort.13', 'w') as outFile: with open('fort.13', 'r') as fort13, open('command.info', 'r') as com: for line in com.read().split('\n'): if line.strip() != '': print >>outFile, line for line in fort13.read().split('\n'): if line.strip() != '': print >>outFile, line
which works, but there should be a better way. Any suggestions?
Edit (2016):
This issue again began to attract attention after four years. I wrote some thoughts on a longer Jupyter laptop here .
The essence of the problem is that my question was related to the (unexpected by me) behavior of readlines . The answer I was aiming for could be better asked, and read().splitlines() better to answer this question.
python cat
JBWhitmore Jul 18 '12 at 1:11 2012-07-18 01:11
source share