Exe*_*n-G 31 python input command-line-interface python-3.x
我在Ubuntu 11.10(Linux)上使用Python 3.2.我的新代码看起来像这样:
text = input("TEXT=")
提示后是否可以获得一些预定义的字符串,所以如果需要我可以调整它?它应该是这样的:
python3 file
TEXT=thepredefinedtextishere
Run Code Online (Sandbox Code Playgroud)
现在我按Backspace3次
TEXT=thepredefinedtextish
Run Code Online (Sandbox Code Playgroud)
现在我按Enter,变量text应该是thepredefinedtextish
Sve*_*ach 27
如果您的Python解释器与GNU readline链接,input()将使用它.在这种情况下,以下应该工作:
import readline
def input_with_prefill(prompt, text):
def hook():
readline.insert_text(text)
readline.redisplay()
readline.set_pre_input_hook(hook)
result = input(prompt)
readline.set_pre_input_hook()
return result
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3760 次 |
| 最近记录: |