簡體   English   中英

如何在python 3中更改光標的位置

[英]how to change the position of the cursor in python 3

我在Windows 10上,我不想安裝新模塊(接受標准庫解決方案)。 我希望用戶輸入的文本從第三行的末尾開始。

我的代碼:

print(" Enter password to unlock the Safe .\n\n password : \n\n\t2 attempts remaining .")
# code to move the cursor to the end of " password : " goes here
x = input()

輸出:

在此輸入圖像描述

想要輸出:

在此輸入圖像描述

ANSI轉義序列似乎也沒有colorama(不幸的是它是一個外部模塊)。

在Windows 10上,您可以使用控制台虛擬終端序列中的 ANSI轉義序列。

在使用它們之前,您需要subprocess.run('', shell=True) (在Python 3.5之前,使用subprocess.call )。 這些序列使您可以找到所需的內容。

警告:同樣是原版Microsoft, 顯示擦除行中擦除文檔部分有問題。 參數12相反。

這應該工作(雖然,實際輸入密碼似乎破壞了布局):

import subprocess
subprocess.run('', shell=True)
print(' enter password : \0337', end='')
print('\n\n\t2 attempts remaining .\0338', end='')
x = input()

用Python 3使用;

print("...", end="")

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM