Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
phone number, to letters conversion
#11
theprask Wrote:It lists all the combinations quite quickly and the list is quite long, so you can't scroll all the way back to see the beginning of the list
If you are in a linux terminal, as it seems because you're using the termios module, you can echo the output to a file, then open that file, for example
Output:
python3 myprogram.py | tee foo.txt && xdg-open foo.txt
You can also use 'less' instead of 'xdg-open' and scroll the result in the terminal with the arrow keys until you press 'q' to quit.
Quote
#12
(Yesterday, 07:32 PM)theprask Wrote: A couple of apologies are in order, first to the sysadmins, I neglected to add the appropriate tags in my first post, I will remember in the future.

Second, to hobbyprogrammer, I was reviewing my copy of your script and it seems I missed a keypress in the shebang at the head and it was trying to interpret python 3 code with the python 2 interpreter. I fixed that, and with the class definition commented out, the program does run fine. I might suggest a small addition though. It lists all the combinations quite quickly and the list is quite long, so you can't scroll all the way back to see the beginning of the list. Here is a function I have found quite useful:
def any_key():
    """A function to pause execution until a key, almost any key
       is pressed.  It does not catch <CTRL>, <ALT>, <SHIFT>, 
       <NUM LOCK> or <CAPS LOCK>. It does not depend on any system calls.
    """
    import tty, sys, termios

    orig_settings = termios.tcgetattr(sys.stdin) #Store current state of input
                                                 #stream
    tty.setraw(sys.stdin) #Set input stream to raw mode
    print("          Any key to continue...")
    sys.stdin.read(1)[0]
    termios.tcsetattr(sys.stdin,termios.TCSADRAIN, orig_settings) #Restore input
                                                                  #stream to original state
    print()     # Final print() to bring the cursor back to the left side of the
                # screen.  Without this, the cursor is left somewhere towards
                # center screen until the <ENTER> key is pressed.
You can define that function at the head of your script, then call it like so during the printing of the final output:
     for A in (list_cnvrt[0]):
        for B in (list_cnvrt[1]):
            for C in (list_cnvrt[2]):
                for D in (list_cnvrt[3]):       
                    for E in (list_cnvrt[4]):      
                        for F in (list_cnvrt[5]):      
                            for G in (list_cnvrt[6]):
                                 print ("(",(cnt),")  ",(A)+(B)+(C)+(D)+(E)+(F)+(G))
                                 print("")
                                 if(cnt % 10 == 0):
                                     any_key()
                                 cnt=cnt+1
I myself keep it with other functions I have found useful in my own module, MyPy.py
and import as needed.


Hi, I'm glad it is working for you now.
Thanks for the handy tip above.
Quote

Top Page

Forum Jump:


Users browsing this thread: 1 Guest(s)