-1

First of all, sorry for my english, it's not my native language. I've searched everywhere but I didn't find anything ... I'd like to know how does progress bars work in python, i've seen some example of 'loading animations' and i did one but for example if there is a file transfered somewhere how can i link the two of them so the bar progression will show the real file loading ? Right now im doing a 'dictionnary' program that create a text file of password combination and I can't figure out how to make a progress bar that show the progress of the process... Here is the code :

import os,itertools

os.system('touch wordlist.txt')
file= open("wordlist.txt", "w")
for n in range(minlenght,maxlength+1):
    for xs in itertools.product(caracters, repeat=n):
        word=''.join(xs)
        file.write(''.join(xs)+"\n")

Thanks in advance.

  • 1
    It looks like you want us to write some code for you. While many users are willing to produce code for a coder in distress, they usually only help when the poster has already tried to solve the problem on their own. A good way to demonstrate this effort is to include the code you've written so far, example input (if there is any), the expected output, and the output you actually get (console output, tracebacks, etc.). The more detail you provide, the more answers you are likely to receive. – Vico Oct 29 '17 at 14:21
  • It's okay your English is fine but you need to explain exactly what you're trying to do (is this a console application? A GUI? We can't read your mind. There are also lots of examples of making different kinds of progress bars if you search the web. So you'll have to actually try something and explain what specific problems you encountered in trying to solve your problem or it's impossible to even know where to begin to help. – Iguananaut Oct 29 '17 at 14:33
  • @Iguananaut Im sorry, you're right, should have been more precise. I just want to know how are progress bars maked in terminal interfaces, not asking someone to code it for me but it's just that I don't see the link between the animation of a progress bar and the action that is done. I'm not asking for a course but just for a little explanation so I can understand how I'll can use it in any case. If you really don't see what I want to answer I'll try to update an example with my program. Thanks – LeeXiaoLong Oct 29 '17 at 14:43
  • That would be best if you updated your question to demonstrate what you're having trouble with. – Iguananaut Oct 29 '17 at 14:49
  • Use `print(x, end='\r')`. The `\r` means that instead of going to the beginning of the next line, the print returns to the beginning of the current line, so the next print will print "over" this line. Try something like `for i in range(5): print('-'*i, end= \r'); time.sleep(1)` to see this for yourself – Patrick Haugh Oct 29 '17 at 15:07
  • Please edit your question instead if you can. – Iguananaut Oct 29 '17 at 15:25
  • Okay, sorry I never posted on that website – LeeXiaoLong Oct 29 '17 at 15:36
  • Thanks @PatrickHaugh but unfortunately that's not what I wanted, I want to link it to an action like the code in my example – LeeXiaoLong Oct 29 '17 at 15:38

2 Answers2

0

try to follow this tutorial in https://pythonprogramming.net/progress-bar-pyqt-tutorial/

you can learn step by step the use of progress bar in a simple application, developed with pyQt libraries, in the download method you can use your code

Guido
  • 76
  • 3
0

I finally did it, thanks to everyone that helped me,if someone else is trying to do it heres how I did it :
I used the progress module which is very easy to use.
In my example I calculated how many lines will be wrote in the file in a variable called possibilities and I added this to my code:

import os, itertools
from progress import IncrementalBar

IncrementalBar = IncrementalBar('Processing', max=possibilities)
#IncrementalBar is a type of loading animation that reach "possibilities"

os.system('touch '+filename+'.txt')
file= open(filename+".txt", "w")
for n in range(minlength,maxlength+1):
    for xs in itertools.product(caracters, repeat=n):
        word=''.join(xs)
        IncrementalBar.next()
        #Each time a line is added, the loading animations get 1 point until she reach "possibilities"
        file.write(''.join(xs)+"\n")
IncrementalBar.finish() #Here the load animation stop
file.close()