首页 文章

如何传递两个python文件,以便在另一个通过控制台读取之前打印(交互式)

提问于
浏览
1

我想要的是这样的:第一个文件只是在第二个文件读取后立即打印

# a.py
print('pepe')
# wait till the other had read
print(23)

第二个程序使用后来的数据

# b.py
name = input()
age = int(input())
print('Hi ' + name + ', you are ' str(age))

所以我可以在控制台中看到:

Hi pepe, you are 23

我想这样做因为,我浪费了很多时间在控制台上输入 . 我想自动完成 .

为了以防万一,我浏览了这个东西很长一段时间,但不知道,这就是为什么我决定在这里问 .

1 回答

  • 0

    几种不同的方式 .

    1)True:一个无限循环,需要你使用某种东西

    while True:
        cmd = input("type something")
        if cmd == 'e':
            do something
        elif cmd == 'f':
            do something else
        else:
            do that last thing
    

    2)输入(“按输入继续”)

    input('press enter to continue')
    

    希望能得到你所需要的......

    您还可以在这里了解更多信息:How do I make python to wait for a pressed key

相关问题