我想用python从用户那里获取多行输入

2024-05-26 00:33:22 发布

您现在位置:Python中文网/ 问答频道 /正文

我想从python中的用户那里获取多行输入,这段代码从用户那里获取多行输入put输出只是最后一行
我制作了这个程序,它使用pywhatkit库将文本转换为手写体,我希望用户可以多行输入,它可以多行输入,但不能打印,只能打印最后一行

这里我从用户那里获取多行输入enter image description here

但在输出中,它只打印我输入的最后一行enter image description here

from colorama import init
from termcolor import colored
import pywhatkit as kit
print("")   
init()
print(colored('Support me on Instagram: @shiva5harma ', 'white', 'on_red'))
print("")
print("Enter/Paste your content. Ctrl-D or Ctrl-Z ( windows ) to save it.")
contents = []
while True:
    try:
        text = input()
    except EOFError:
        break
    contents.append(text)
print("")
print("-- Lcation Example: C:/User/owner/Desktop/image_name.png  --")
print("")
path=str(input("Enter Location where to store image\n"))
try:
  print("")
  print("I'm working on it Please Wait.......\n")
  kit.text_to_handwriting(text,path)
except:
   print("Error Occured")
finally:
   print("Your Image is ready !! Your will find your Image here\n",path)

Tags: topathtext用户fromimportyourinit
1条回答
网友
1楼 · 发布于 2024-05-26 00:33:22

您在此行中使用了错误的参数:

kit.text_to_handwriting(text,path)

我认为应该是这样的:

full_text = "\n".join(contents)  # Make one big string of all individual input lines
kit.text_to_handwriting(full_text,path)  # Use the new parameter

相关问题 更多 >