Well you can write a tab by using the escape character and t. So if you were writing a tab to a file you would go something like this:
f = open("File.txt",'w')
f.write("\t This will be indented one tab space!")
f.close()
So the \t is the escape sequence used to indicate a tab.
Hope that helps :)
Paul Thompson
Veteran Poster
1,119 posts since May 2008
Reputation Points: 264
Solved Threads: 183
you can try this
from __future__ import with_statement
fil = open('C:\\Documents and Settings\\Desktop\\file2.txt','rb')
resultfile = open('C:\\Documents and Settings\\Desktop\\j3.txt','wb')
for line in fil:
if len(line.split('|')) >= 3:
i = float(line.split('|')[2])
if 90 <= i < 100:
resultfile.write('%s\r\n'%''.join(line.replace('|','\t')))
baki100
Junior Poster in Training
79 posts since Apr 2009
Reputation Points: 12
Solved Threads: 14
You mean something like this:
# data string read from a file
data = """\
gnl|dbSNP|rs13484118 gi|62750812|ref|NC_005111.2|NC_005111 95 20 1 0 68 87 31017559 31017578 4.4 32.3
gnl|dbSNP|rs13484118 gi|62750812|ref|NC_005111.2|NC_005111 91.67 24 2 0 63 86 35247737 35247714 4.4 32.3
gnl|dbSNP|rs13484118 gi|62750812|ref|NC_005111.2|NC_005111 91.67 24 2 0 64 87 40549054 40549031 4.4 32.3
gnl|dbSNP|rs13484118 gi|62750812|ref|NC_005111.2|NC_005111 92 24 2 0 63 86 42462636 42462659 4.4 32.3
gnl|dbSNP|rs13484118 gi|62750812|ref|NC_005111.2|NC_005111 95 20 1 0 63 82 45774066 45774085 4.4 32.3
"""
new_data = ""
for line in data.split('\n'):
# replace each space with a tab
line = line.replace(" ", "\t")
new_data += line + '\n'
# test only ...
print(new_data)
# now write new_data string to a file
Ene Uran
Posting Virtuoso
1,722 posts since Aug 2005
Reputation Points: 625
Solved Threads: 212