Reputation: 1
I am beginning to learn python and am having some trouble getting n output to print to txt file on the desktop. I want it to be Mac and windows comptible. I keep getting a syntax error at a line that doesn't exist or no such file directory on line 4. I am trying to create the text file.
import os
os.path.join("~","Desktop")
output_file = open(os.path.join("~","Desktop","PythoBLASTout.txt"),"w")
from Bio import SearchIO
E_VALUE_THRES = 0.01
with open('/Users/evanclark/conesnail.xml', 'rU') as input:
for qresult in SearchIO.parse(input, "blast-xml"):
hits = qresult.hits
query_id = qresult.id
if len(hits) > 0:
target_id = hits[0].id
evalue = hits[0].hsps[0].evalue
if evalue < E_VALUE_THRES:
print("%s\t%s" % (query_id, target_id))
#output_file.write("%s\t%s" % (query_id, target_id)
Upvotes: 0
Views: 35
Reputation: 7030
If you want to do tilde expansion you need to tell Python to do this explicitly:
output_file = open(os.path.expanduser(os.path.join("~", ...)), "w")
Upvotes: 1