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

  • SEARCH
  • Home
  • 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 8083333
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T17:25:55+00:00 2026-06-05T17:25:55+00:00

Wget prints out speed information to stdout in a very clear manner, where the

  • 0

Wget prints out speed information to stdout in a very clear manner, where the speed is shown and refreshed whilst the file is downloaded, and a bar scrolls across the screen. I’d like to replicate this sort of output, in a Python program. How is this possible?

I thought the curses library should be able to do this; this is what I came up with:-

import curses, time

class Speeder( object ):
    """Show and refresh time and download speed in a curses interface."""
    t1 = 0. # start time
    t  = 0. # current time
    tf = 0. # end time
    def start(self, filename=None ):
        """Start timer"""
        self.t1 = self.t = time.time()
        curses.use_env(True)
        curses.initscr()
        self.win = curses.newwin(4, 0)
        if filename is not None:
            self.win.addnstr(filename, 50 )
            self.win.refresh()

    def update(self, rbytes):
        """Refresh speed."""
        t = time.time()
        td = t - self.t
        self.t = t
        speed = rbytes / td 
        self.win.addstr(0,54,str('{0:.02f} B/s'.format(speed)))
        self.win.refresh()

    def end(self):
        """End timer"""
        self.tf = time.time() 
        curses.endwin()


try:
    speed = Speeder()
    speed.start(filename='foo.bar')
    for i in xrange(10):
        time.sleep(0.5)
        speed.update(200)
finally:
    speed.end()

The problem is that it takes up an entire window, and I only really need a line at a time. I’d rather not push all the command line history back above the terminal window. Please correct me if I’m wrong, but I currently think curses apps always take up the entire terminal window.

So I had a look at the tty and termios modules, but I can’t find any examples doing what I want to do.

Finally, I came across a blog post which does it by simply writing some special characters to sys.stdout. Applying his code to my Speeder class, I came up with this:-

import sys
class Speeder( object ):
    """Show and refresh time and download speed."""
    t1 = 0. # start time
    t  = 0. # current time
    tf = 0. # end time
    def start(self, filename=None ):
        """Start timer"""
        self.t1 = self.t = time.time()
        if filename is not None:
            sys.stdout.write( '\r\x1b[K' + filename.ljust(50) )
            sys.stdout.flush()

    def update(self, rbytes):
        """Refresh speed."""
        t = time.time()
        td = t - self.t
        self.t = t
        speed = '{0} B/s'.format( rbytes / td )
        sys.stdout.write( "\r\x1b[K" + speed.rjust(65) )
        sys.stdout.flush()

    def end(self):
        """End timer"""
        self.tf = time.time()
        sys.stdout.write('\n')

This has fewer lines of code, which I like, but tbh I don’t have a clue what’s going on, or how to modify it to only update part of the line, similar to the curses.addstr function. Currently, the filename is overwritten with white-space. I could of course modify the class to construct the entire line each time from python, but I’d like to understand this in order to tailor it to my own needs.

The author says this is possible only on VT100 terminals. So I guess this would only work on Unix terminals then? That’s fine, but are there any Unix terminals that this would not work on?

Is there better documentation on the subject, or more complicated examples (e.g. updating multiple lines, one line of many, or single characters on a line), preferably for Python? This doesn’t seem like a feature of Python, but the tty, which is why I guess I’ve failed to find anything. Is there a man page or something I should read?

  • 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-06-05T17:25:56+00:00Added an answer on June 5, 2026 at 5:25 pm

    The code above is using ANSI escape codes: https://en.wikipedia.org/wiki/ANSI_escape_code. I think that’s the documentation you are looking for when trying to grok the code you found.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

exec('wget --progress=bar http://technabob.com/blog/wp- content/uploads/2011/04/light_up_pi_symbol_1.jpg'); echo 1; output 1 ie the download is not working.I
wget http://www.example.com/file.doc downloads that file to the local disk. What is the equivalent of
My intention is to output log of recursive wget in one line, 'status bar'-like.
I have a .php file that I would like wget to download, it will
I have been trying to figure out a way to make wget only create
I use: wget --no-check-certificate --http-user=user --http-password=secret --header=Content-Type:text/xml --post-file=request.xml https://mydominain.com/xml to send an xml request.
Simple task: I have a script with line: qx(wget -P $destination $file) || die
I can download a CSV file from Google Docs with wget : wget --no-check-certificate
Possible Duplicate: wget: Unsupported scheme on non-http URL For example: export URI=file:///myhost/system.log How to
wget --output-document=/var/www/projects/meme/upload/1341233172.jpeg http://memecaptain.com/i?u=http://cdn.memegenerator.net/images/400x/528461.jpg&t1=dm&t2=cmks I used following command to download a meme but wget is

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.