2017-06-26 42 views
2

我想通過使用os.system('python') 來訪問python shell的cmd版本。但是,這隻適用於python shell而不是程序。考慮如果我想使用從程序運行的os.system('cmd'),這尤其令人困惑。我在做什麼,以便不能通過程序中的命令打開python shell?爲什麼它對cmd起作用?Python os.system('python')只能在shell中運行

+0

爲了澄清,你是否試圖從一個python腳本內打開交互式python shell? –

+0

我不知道; 'os.system(「python」)'在交互式和腳本(程序)模式下都可以正常工作。你能發佈你的代碼和你得到的實際輸出嗎?我跟着我的輸入命令,以確保在我尋找解決方案時沒有任何東西會關閉。 – Prune

+0

適合我。但是,我正在使用Linux。也許Windows在將終端窗口與Python關聯時遇到問題? –

回答

1

我想你有一個python腳本,並且希望能夠在腳本執行期間的某個時候打開一個交互式python shell。如果這是你想要的,那麼這應該工作:

import code 

# do some stuff 
# open interactive python shell using the code library 
code.interact(local=locals())