Posts: 63
Threads: 22
Joined: Aug 2017
Hi all.
I found that when I run the print command with "\b" I can produce a tick symbol.
Does anyone have any other tips they would like to share about this function?
print("Microphone_Head ", end ="") ; print("is in the house \b") Output: Microphone_Head is in the house
PS. I'm running Python on a RaspberyPi 2B+, and there really is a tick symbol honest  .
Posts: 1,950
Threads: 8
Joined: Jun 2018
Apr-11-2019, 11:24 AM
(This post was last modified: Apr-11-2019, 11:24 AM by perfringo.)
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)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 4,795
Threads: 76
Joined: Jan 2018
Try print(''.join(chr(9812 + x) for x in range(12)))
Posts: 1,950
Threads: 8
Joined: Jun 2018
Apr-11-2019, 12:27 PM
(This post was last modified: Apr-11-2019, 12:45 PM by perfringo.)
(Apr-11-2019, 11:58 AM)Gribouillis Wrote: Tryprint(''.join(chr(9812 + x) for x in range(12)))
King is smaller than pawn
>>> '♔' < '♙'
True
Little animation:
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()
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 7,320
Threads: 123
Joined: Sep 2016
for word in 'f-strings are awesome'.split():
print(f'{word.capitalize():\N{smiling face with sunglasses}^15}')
Posts: 63
Threads: 22
Joined: Aug 2017
Apr-12-2019, 08:30 AM
(This post was last modified: Apr-12-2019, 08:50 AM by microphone_head.)
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  . I tried the following:
print("MH\rb")
print("MH\Rb") and got 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  ?
Posts: 7,320
Threads: 123
Joined: Sep 2016
(Apr-12-2019, 08:30 AM)microphone_head Wrote: 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: Upgrade your python version,f-string was new in Python 3.6.
Like this it will work in older version.
import time
import sys
animation = '|/-\\'
for i in range(25):
time.sleep(0.1)
sys.stdout.write("\r{}".format(animation[i % len(animation)]))
sys.stdout.flush()
Posts: 1,950
Threads: 8
Joined: Jun 2018
Apr-12-2019, 09:35 AM
(This post was last modified: Apr-12-2019, 09:36 AM by perfringo.)
(Apr-12-2019, 08:30 AM)microphone_head Wrote: 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.
FYI. I'm running the Python on a Raspberry Pi 2B+.
This code uses f-strings available from Python >= 3.6. If you replace this with following, it should work:
sys.stdout.write("\r" + animation[i % len(animation)]) ninjad by snippsat
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Posts: 63
Threads: 22
Joined: Aug 2017
(Apr-12-2019, 09:34 AM)snippsat Wrote: (Apr-12-2019, 08:30 AM)microphone_head Wrote: 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: Upgrade your python version,f-string was new in Python 3.6. Like this it will work in older version. import time import sys animation = '|/-\\' for i in range(25): time.sleep(0.1) sys.stdout.write("\r{}".format(animation[i % len(animation)])) sys.stdout.flush()
Ok, it runs but this is the output on my machine:
Output: |
/
-
\
|
/
-
\
|
/
-
\
|
/
-
\
|
/
-
\
|
/
-
\
|
Something weird is going on. When I copied the output from my shell window it all appeared on one line, like a list of musical notes. But it does run.
Posts: 1,950
Threads: 8
Joined: Jun 2018
Apr-12-2019, 09:52 AM
(This post was last modified: Apr-12-2019, 09:52 AM by perfringo.)
(Apr-12-2019, 08:30 AM)microphone_head Wrote: 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 ?
Something along those lines (no f-strings, should work right away)?
import sys, time
def status_bar(activity, progres):
length = 25
block = int(round(length*progres))
msg = "\r{0}: [{1}] {2}%".format(activity, "#"*block + "-"*(length-block), round(progres*100, 2))
if progres >= 1:
msg += " Ready\r\n"
sys.stdout.write(msg)
sys.stdout.flush()
# usage
for i in range(100):
time.sleep(0.1)
status_bar('Activity', i/100.0)
status_bar('Activity', 1)
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
|