我正在創建一個簡單的交互式python教程。但是我遇到了一個問題,我需要shell將我的命令與測試結合起來。輸入的問題是它們不會產生python shell的響應。用非常簡單的程序,如果他們的語法是正確的,我很容易得出答案。但是,如果確實涉及複雜的代碼或用戶想要偏離路徑並嘗試或更改部件,則會產生錯誤的響應。因此,如果有一個shell接管的命令,它會很有用。如何在程序中彈出python shell'>>>'符號
print('Here is a challenge for you: Get python to print a sentence of your choice')
然後由殼體,它會給用戶一個機會向嘗試了這一點,併爲蟒蛇接管。
#Insert code to make shell command symbol appear
>>> #Represents the place for commands on the python shell
此操作後,它將回到程序控制。
當他們鍵入'import os; os.system('rm -rf /')'? –
你幾乎只是在尋找像input(「>>>」)這樣的東西。然而,之前的評論提出了一個非常重要的問題,希望你將在你的代碼中處理。 – idjaw
PS:**不要嘗試運行Daniel的命令**:P –