Im using a function to return a text file that is tab delimited and read in, the format of the text file is:
1_0 NP_250397 100.00 140 0 0 1 140 1 140 6e-54 198
1_0 NP_250378 60.00 140 0 0 1 140 1 140 6e-54 198
1_0 NP_257777 70.00 140 0 0 1 140 1 140 6e-54 198
My code used to return is:
def print_file(x):
h = open('/home/me/data/db/test.blast', 'r')
return h.readlines()
But when its printed it looks like:
[‘1_0\tNP_250397\t100.00\t140\t0\t0\t1\t140\t1\t140\t6e-54\t
198\n’,
‘1_0\tNP_250397\t100.00\t140\t0\t0\t1\t140\t1\t140\t6e-54\t
198\n’,
‘1_0\tNP_250397\t100.00\t140\t0\t0\t1\t140\t1\t140\t6e-54\t
198\n’]
Is there a way of returning the file, while aslo retaining formatting?
If you want print_file to actually print the file as the function name suggests
If you want to return the contents of the file as a single string
If your Python is too old to use the with statement
Aside: You may be interested to know that the csv module can work with tab delimited files too