输出保持垂直打印

Output Keeps Printing Vertically

我能够编写一个 API 调用来从 public API 中检索歌词(特别是 Dance Gavin Dance 的尴尬。事情是,当它打印时,它打印逐个字母的歌词,而不是垂直 pf 它在 API 上显示的方式。这是代码:

import json
import requests

api_url_base = 'https://api.lyrics.ovh/v1/'
headers = {'Content-Type': 'application/json',
           'charset': 'utf-8'}

def get_lyrics_info():

        api_url ='{0}Dance%20Gavin%20Dance/Awkward'.format(api_url_base)
        response = requests.get(api_url, headers=headers)

 if response.status_code == 200:
       return json.loads(response.content.decode('utf-8'))
   else:
       return None

lyric_info = get_lyrics_info()

if lyric_info is not None:
   print("Here is your info: ")
   for lyrin in lyric_info["lyrics"]:
      print(lyrin)

else:
   print('[!] Request Failed')

这是输出的样子(这只是输出的一部分,只是为了向您展示它的样子):

D
o
n
'
t

m
a
k
e

t
h
i
s

a
w
k
w
a
r
d

我试过使用 wrap() 函数、fill() 函数,但变量 "lyrin" 不是字符串。我该如何解决这个问题?

for lyrin in lyric_info["lyrics"] 将遍历所有 chars 使用 for lyrin in lyric_info["lyrics"].split('\n'):

或者sys.stdout.write(lyrin)

import json
import requests

api_url_base = 'https://api.lyrics.ovh/v1/'
headers = {'Content-Type': 'application/json',
           'charset': 'utf-8'}

def get_lyrics_info():
   api_url ='{0}Dance%20Gavin%20Dance/Awkward'.format(api_url_base)
   response = requests.get(api_url, headers=headers)

   if response.status_code == 200:
       return json.loads(response.content.decode('utf-8'))
   else:
      return None

lyric_info = get_lyrics_info()

if lyric_info is not None:
      print("Here is your info: ")
      for lyrin in lyric_info["lyrics"].split('\n'):
         print(lyrin)

else:
       print('[!] Request Failed')

import json
import requests
import sys

api_url_base = 'https://api.lyrics.ovh/v1/'
headers = {'Content-Type': 'application/json',
           'charset': 'utf-8'}

def get_lyrics_info():
   api_url ='{0}Dance%20Gavin%20Dance/Awkward'.format(api_url_base)
   response = requests.get(api_url, headers=headers)

   if response.status_code == 200:
       return json.loads(response.content.decode('utf-8'))
   else:
      return None

lyric_info = get_lyrics_info()

if lyric_info is not None:
      print("Here is your info: ")
      for lyrin in lyric_info["lyrics"]:
         sys.stdout.write(lyrin)

else:
       print('[!] Request Failed')