My python script opens a gzip file from FTP and reads it. Every time I run the script .gz files are downloaded to my Harddisk (Sites/htdocs folder as its a python cgi). I dont want to download the files to my harddisk or else delete the files after execution of script.
Here is snapshot of my script:
u = 'http://hapmap.ncbi.nlm.nih.gov/downloads/frequencies/2010-05_phaseIII/'
filename1 = 'allele_freqs_chr' + chromosomes[i] + '_' + populations[0] + '_phase3.3_nr.b36_fwd.txt.gz'
url = u + filename1
try:
site = urllib.urlretrieve(url,filename1)
except IOError:
print >> sys.stderr,'Error opening URL.\n'
try:
f1 = gzip.open(filename1, 'rb')
except IOError:
print >> sys.stderr, 'Error opening file1.\n'
sys.exit(1)
line=f1.readline()
# ...
I appreciate your suggestions.
os.unlink(filename1)should work. Also, usefinally:in yourtry:block to close the file descriptor like so: