Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6677143
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T04:04:51+00:00 2026-05-26T04:04:51+00:00

My python script opens a gzip file from FTP and reads it. Every time

  • 0

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.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T04:04:51+00:00Added an answer on May 26, 2026 at 4:04 am

    os.unlink(filename1) should work. Also, use finally: in your try: block to close the file descriptor like so:

    import os
    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)
    else:
        line = f1.readline()
        # ....
    finally:
        try:
            f1.close()
        except:
            pass
    
    os.unlink(filename1)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm writing a python script that generates html file. Every time I run this
This is my first question. My python script opens and reads from a present
Is it possible for a python script to open its own source file and
I am trying to create a python script that opens a single page at
I have a Python script so far that does what I it to... Opens
File associations on my machine (winxp home) are such that a python script is
I am writing a python script in order to write a tex file. But
This is my python script which creates a test.txt file when executed. when I
I want to run some command in python script import fcntl KDSETLED = 0x4B32
I'm writing a python script checking/monitoring several server/websites status(response time and similar stuff), it's

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.