简体   繁体   中英

How to rotate a character by 90 degrees in python?

I'm trying to rotate the character | sideways by 90 degrees, think of a longer - and then print it.

would appreciate the help as to how I can do that?

For converting '|' char to 90 degree, we can replace with all chars '|' to '—' chars.


s1 = "Example | text | with | horizontal | string"

def RotateCharacter90(s1):
    s2 = s1.replace( "|", "—")
    return s2

print(RotateCharacter90(s1))

""" OUTPUT: Example — text — with — horizontal — string """

Can you just print an em dash, "—"? In many fonts, an em dash is as long as the font's letters are tall.

Here's some example code that "rotates" the "|"symbol in the console in a complete circle for a loading animation by replacing it with em dashes and forward and backward slashes.

import time
import sys

def loadingAnimation():
    #Run for 10 seconds
    timeToRun = time.time() + 10
    while time.time() < timeToRun:
        wheelAnim = ['|','/','—','\\']
        for frame in wheelAnim:
            sys.stdout.write('\rLoading... %s' % frame)
            #Hold each frame for 0.15 seconds
            time.sleep(0.15)
            sys.stdout.flush()
          
    sys.stdout.write('\rLoading... complete.\n')
  
loadingAnimation()

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM