I am (trying) to write a tool that will open a file based on user input. I want to eventually write the results of the script into a file and store it into the same directory as the input file.
I currently have this
from Bio import SeqIO
import os, glob
var = raw_input("what is the path to the file (you can drag and drop):")
fname=var.rsplit("/")[-1]
fpath = "/".join(var.rsplit("/")[:-1])
os.chdir(fpath)
#print os.getcwd()
#print fname
#for files in glob.glob("*"):
# print files
with open(fname, "rU") as f:
for line in f:
print line
I do not understand why I cannot open the file. Both the "os.getcwd" and the "glob.glob" part show that I successfully moved to the users directory. In addition, the file is in the correct folder. However, I cannot open the file... any suggestions would be appreciated
os.path.join(fname, fpath)instead of the contortions you currently go through with thersplits andjoins?open(fpath + '/output.txt', 'w')or whatever for the output/home/user/test.txtas input. Though as others have recommended there are probably cleaner ways to go about what you're doing.