本文整理匯總了Python中cjh.cli.Cli.get_keypress方法的典型用法代碼示例。如果您正苦於以下問題:Python Cli.get_keypress方法的具體用法?Python Cli.get_keypress怎麽用?Python Cli.get_keypress使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類cjh.cli.Cli
的用法示例。
在下文中一共展示了Cli.get_keypress方法的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: main
# 需要導入模塊: from cjh.cli import Cli [as 別名]
# 或者: from cjh.cli.Cli import get_keypress [as 別名]
def main():
"""
Reads in a specified file, removes trailing whitespace, and re-saves.
"""
# Open file and store lines as str list
try:
file_handler = open(ARGS.filename, 'r+')
except IOError:
print(traceback.format_exc()) # pylint: disable=C0325
sys.exit()
lines_of_text = file_handler.readlines()
file_handler.seek(0)
# Preview and write text back to file and close file
print(lines_of_text) # pylint: disable=C0325
Cli.wait()
string = ''
preview_string = ''
for index, _ in enumerate(lines_of_text):
string += lines_of_text[index].rstrip() + '\n'
preview_string = string.strip() + Cli.term_fx('b', 'EOL')
pydoc.pipepager(preview_string, cmd='less -R')
try:
char = Cli.get_keypress('Write to file?')
assert char == 'y'
file_handler.write(string)
except AssertionError:
print('File not saved. Good bye.') # pylint: disable=C0325
finally:
file_handler.close()