Search code examples
pythonprintingline

How can I print the last line of code on a seperate line?


I'm trying to print out the last line of code on a separate line, as it always prints on the same line as the spinner?

I've already tried removing the sleep function.

from halo import Halo
import time
from colorama import Fore

name = input("TARGET:\n")

spinner = Halo(text='\nCalling: ' + name, spinner='dots')

spinner.start('\rCalling: ' + name)

time.sleep(5)

print(Fore.GREEN + 'Call Successful! [Internet = POSITIVE]')

I expect the output of the last line to be on a separate line when printed.


Solution

  • Two options for you. On my system (Mac) your code doesn't seem to do what it's supposed to, it just prints loads of lines rather than a spinner. In any case here are options that I would expect to work:

    Stop the spinner

    name = input("TARGET:\n")
    
    spinner = Halo(text='\nCalling: ' + name, spinner='dots')
    
    spinner.start('\rCalling: ' + name)
    
    time.sleep(5)
    
    spinner.stop()
    
    print(Fore.GREEN + 'Call Successful! [Internet = POSITIVE]')
    

    Add a newline

    name = input("TARGET:\n")
    
    spinner = Halo(text='\nCalling: ' + name, spinner='dots')
    
    spinner.start('\rCalling: ' + name)
    
    time.sleep(5)
    
    print("\n" + Fore.GREEN + 'Call Successful! [Internet = POSITIVE]')