我似乎找不到一种简单的方法来编写代码,找到要格式化的项目数,向用户请求参数,并将它们格式化为原始格式。在
下面是我要做的一个基本示例(用户输入在“>>>之后开始”):>>> test.py
What is the form? >>> "{0} Zero {1} One"
What is the value for parameter 0? >>> "Hello"
What is the value for parameter 1? >>> "Goodbye"
然后程序将使用print(窗体.格式())显示格式化输入:
^{pr2}$
但是,如果窗体有3个参数,它将要求参数0、1和2:>>> test.py (same file)
What is the form? >>> "{0} Zero {1} One {2} Two"
What is the value for parameter 0? >>> "Hello"
What is the value for parameter 1? >>> "Goodbye"
What is the value for parameter 2? >>> "Hello_Again"
Hello Zero Goodbye One Hello_Again Two
这是我能想到的最基本的应用程序,它将使用可变数量的东西来格式化。我已经知道如何使用vars()在需要时生成变量,但是字符串格式()无法接受列表、元组或字符串,我似乎无法使“.format()”调整到要格式化的内容的数量。在