简体   繁体   English

如何将python中的一个字符旋转90度?

[英]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.横向 90 度,想到更长的 - 然后打印出来。

would appreciate the help as to how I can do that?我将不胜感激关于我如何做到这一点的帮助?

For converting '|'用于转换 '|' char to 90 degree, we can replace with all chars '|' char 到 90 度,我们可以替换为所有字符 '|' 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.在许多 fonts 中,破折号的长度与字体的字母一样长。

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.控制台中的符号在一个完整的圆圈中用于加载 animation,将其替换为短划线和正斜杠和反斜杠。

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()

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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