【问题标题】:Crawl makes input release "None" | Python抓取使输入释放“无” | Python
【发布时间】:2020-07-01 05:48:54
【问题描述】:

所以我绝对知道这样说:

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)

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

【问题讨论】:

标签: python function input printing


【解决方案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 是我的标准输入。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-25
    • 2017-05-17
    • 2018-11-17
    • 2023-04-03
    • 1970-01-01
    • 2020-08-04
    相关资源
    最近更新 更多