Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
print: Tips and tricks
#6
Quote:
import time 
import sys 
 
animation = '|/-\\' 
for i in range(25): 
    time.sleep(0.1) 
    sys.stdout.write(f"\r{animation[i % len(animation)]}")
    sys.stdout.flush() 

Do I need to import another library?

I've tried running this in Python 2.7.9 and Python 3.4.2 and I cant't get it to work. It reports a syntax error on the following line:
sys.stdout.write(f"\r{animation[i % len(animation)]}")
FYI. I'm running the Python on a Raspberry Pi 2B+.

(Apr-11-2019, 11:24 AM)perfringo Wrote:
Quote:Unless an 'r' or 'R' prefix is present, escape sequences in string and bytes literals are interpreted according to rules similar to those used by Standard C.
Escape sequence \b meaning is "ASCII Backspace (BS)". Other sequences and their meanings are available in Python documentiation (String and Byte Literals)

Hi perfringo,

I don't understand what you mean. I've had a quick read of the link you gave Confused . I tried the following:

print("MH\rb")
print("MH\Rb")
and got Huh
Output:
MH b MH\Rb
I was toying with the idea of being able to write some chars to the Python shell before deleting it to make a progress bar. Can you give an example Angel ?
Reply


Messages In This Thread
print: Tips and tricks - by microphone_head - Apr-11-2019, 09:33 AM
RE: print: Tips and tricks - by perfringo - Apr-11-2019, 11:24 AM
RE: print: Tips and tricks - by Gribouillis - Apr-11-2019, 11:58 AM
RE: print: Tips and tricks - by perfringo - Apr-11-2019, 12:27 PM
RE: print: Tips and tricks - by microphone_head - Apr-12-2019, 08:30 AM
RE: print: Tips and tricks - by perfringo - Apr-12-2019, 09:35 AM
RE: print: Tips and tricks - by perfringo - Apr-12-2019, 09:52 AM
RE: print: Tips and tricks - by snippsat - Apr-11-2019, 01:15 PM
RE: print: Tips and tricks - by snippsat - Apr-12-2019, 09:34 AM
RE: print: Tips and tricks - by microphone_head - Apr-12-2019, 09:47 AM
RE: print: Tips and tricks - by microphone_head - Apr-12-2019, 10:07 AM
RE: print: Tips and tricks - by snippsat - Apr-12-2019, 10:45 AM
RE: print: Tips and tricks - by microphone_head - Apr-12-2019, 04:03 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Beginner/Intermediate Tips Ex_database 1 2,112 Sep-27-2019, 04:24 PM
Last Post: Larz60+
  Quick tips and tricks for python juliopa 2 42,777 Jul-03-2019, 09:41 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020