Reading and Writing Files
cp /net/bmc-pub15/data/bmc/public/BCC/external/teaching/IntroToPython/* ./Examples
In [1]: fin=open('seq.txt')
In [2]: fin=open('/net/rowley/ifs/data/bcc/dropbox/teaching_python/seq.txt')
In [3]: fin=open('seq.txt','r')
In [1]: Aa="GLECDGRTNLCCRQQFF"
In [2]: fo=open('seq2.txt','w')
In [3]: fo.write(Aa)
In [4]: fo.close()
Out[4]: <function close>
In [5]: less seq2.txt
GLECDGRTNLCCRQQFF
*no need to remember to close the file handler if using "with" statement
In [1]: with open('seq2.txt','w') as fo:
...: fo.write("ABC")
...:
In [2]: less seq2.txt
ABC
Note: writing to a file will delete the existing content of the fileLast updated
Was this helpful?
