簡體   English   中英

如何在python中打開shell窗口輸出打印實時調試信息

[英]how to open a shell window output print real time debug information in python

我可以在不中斷代碼執行順序的情況下打開shell窗口以使用python打印調試信息嗎?

例如:

def foo(b):
    print b

for a in range(0, 100):
    print a       # normally this will be used for on-the-fly simple debugging purpose 
                  # and will mess the console output of foo()          
    foo(a)

我可以做類似的事情:

newshell = <new cmd.exe or bash>

for a in range(0, 100):
    newshell.print(a)       # information will be printed to new opened shell  
    foo(a)

提前致謝。

您可以:

  1. 使用python日志記錄。 http://docs.python.org/2/library/logging.html
  2. 只需寫入文件並從終端執行:$ tail -f output.txt
  3. 寫入框內已打開的終端(即linux),寫入文件描述符/ dev / pts / X(使用X:1,2 ...,用$ who可以看到正確的數字)

我們不需要外殼就可以打印東西。 您可以使用Tkinter Text 小部件

from Tkinter import Tk, Text, END

root = Tk()
text = Text(root)
text.pack()

def foo(b):
    print b

for a in range(0, 100):
    text.insert(END, str(a)+"\n")
    text.see(END)
    text.update()
    foo(a)

text.wait_window()  # wait until we close the window

暫無
暫無

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

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