首页 > 解决方案 > 抓取使输入释放“无” | 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)

它产生正确但有一个问题......它会立即产生它,我的抓取功能应该一个字母一个字母地拖出来。请帮忙。

标签: pythonfunctioninputprinting

解决方案


input如果给定参数,内置函数将打印参数。

提示字符串(如果给定)将在读取输入之前打印到标准输出,而没有尾随换行符。

所以你不应该给input.
您可以简单地将调用crawlinput.

注意:我删除了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 是我的标准输入。


推荐阅读