raw_input没有在readline中留下历史记录

los*_*eek 4 python history readline tab-completion

有没有一种方法可以使用raw_input而不在readline历史记录中留下一个符号,这样它就不会在tab完成时显示?

Dav*_*ick 6

你可以做一个类似的功能

import readline

def raw_input_no_history():
    input = raw_input()
    readline.remove_history_item(readline.get_current_history_length()-1)
    return input
Run Code Online (Sandbox Code Playgroud)

并调用该函数而不是raw_input.您可能不需要减1取决于您从哪里调用它.