python - 抓取使输入释放“无” | Python
问题描述
所以我绝对知道这样说:
x = input(print('hello what is ur name uwu:')
会产生:
hello what is ur name uwu:None
但这是我的代码:
import sys
import time
from colorama import Fore
def crawl(text,ti):
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(ti)
input(crawl(Fore.RED + 'Well, hello there my dear player!',0.1))
正如预期的那样......它产生:
Well, hello there my dear player!None
我试过这样做:
crawl(input(Fore.RED + 'Well, hello there my dear player!'),0.1)
它产生正确但有一个问题......它会立即产生它,我的抓取功能应该一个字母一个字母地拖出来。请帮忙。
解决方案
input
如果给定参数,内置函数将打印参数。
提示字符串(如果给定)将在读取输入之前打印到标准输出,而没有尾随换行符。
所以你不应该给input
.
您可以简单地将调用crawl
和input
.
注意:我删除了colorama
依赖项,因为它与您的问题无关。
import sys
import time
def crawl(text, ti):
for char in text:
sys.stdout.write(char)
sys.stdout.flush()
time.sleep(ti)
crawl('Well, hello there my dear player!', 0.1)
x = input()
print(x)
输出:
Well, hello there my dear player!5
5
5 是我的标准输入。
推荐阅读
- android - 设置活动标题使用哪个 Android 字符串
- javascript - 如何基于布尔属性有条件地在 ReactJS 中应用嵌套的 SCSS 类?
- python - Python Bokeh:如何更新切换按钮 - 在主程序中定义 - 在子程序中
- docker - 自托管注册表中的某些层的 Docker 拉取失败
- intellij-idea - Intellij 如何忽略有错误的文件?
- facebook - facebook 通知图表方法现已弃用,但文档没有新方法
- bitbucket - 如何使用已更改名称的更新文件更新远程文件?
- javascript - 多个 p5.image 的问题
- spring-security - 如何向 Cognito 发布的 id_token 添加“组”自定义声明?
- r - 固定效应 logit 套索模型