Giter Site home page Giter Site logo

Comments (5)

wolph avatar wolph commented on June 18, 2024

That is intended behaviour to be honest :)

The reason for always requiring a formatstring is consistency in spacing. With an empty formatstring it would move the other stuff in the progressbar around.

You can work around it by using a space ' ' or an invisible character such as '\x00'

from python-progressbar.

SimonLammer avatar SimonLammer commented on June 18, 2024

@wolph I'm not sure I understand. Could you give an example where an empty-string result of ETA would "move the other stuff in the progress bar around"?

from python-progressbar.

wolph avatar wolph commented on June 18, 2024

Just take a look at this code:

import time
import progressbar


bar = progressbar.ProgressBar(widgets=[
    progressbar.ETA(format_finished=' '),
    ' Some text here ',
    progressbar.Bar(),
])

for i in bar(range(5)):
    bar.update(i)
    time.sleep(0.1)

time.sleep(1.00)

The output looks something like this:

ETA:   0:00:00 Some text here |#########                                      |
ETA:   0:00:00 Some text here |##################                             |
ETA:   0:00:00 Some text here |############################                   |
ETA:   0:00:00 Some text here |#####################################          |
  Some text here |############################################################|

As you can see, the text moves and the bar becomes much wider suddenly. That can be a bit confusing :)

from python-progressbar.

SimonLammer avatar SimonLammer commented on June 18, 2024

I see.
However, this also happens when setting format_finished-' ' which you suggested previously.

import progressbar
for value in progressbar.progressbar(
    [1],
    widgets=[
        "Foo",
        progressbar.ETA(
            format_finished=" ",
        ),
        "Bar",
    ],
):
    print()
FooETA:  --:--:--Bar
Foo Bar

Similarly, the invisible character you suggested also does not preserve ETA's output length (format_finished="\x00"):

FooETA:  --:--:--Bar
FooBar

This behaviour may look subpar, but that's a subjective notion. Some users may want to have it that way, some may not.
If those two options you suggested don't preserve the output length of ETA, why should explicitly setting format_string=""?

from python-progressbar.

wolph avatar wolph commented on June 18, 2024

Oops... didn't notice your reply.

It actually does work in your example, in both cases :)
The reason that it doesn't appear to work is because you're not seeing the format_finished here but the format_not_started. The progressbar overwrites the current line and with the print() statement you're creating a new line so the old line won't be overwritten.

If you replace the print() with pass you'll see the proper output

If you want to use print statements in your code I would suggest enabling output redirection: https://github.com/wolph/python-progressbar#combining-progressbars-with-print-output

from python-progressbar.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.