簡體   English   中英

在 python 中,如何確定本地 scope 中的變量值

[英]In python, how can you determine the values of variables in a local scope

出於調試目的,我發現如果我可以打印本地 scope 中的變量並且僅打印本地 scope 中的變量,這可能是有益的。

樣本:

def showAuthUser(self):
    """Make a request to the campfire server. 

    Returns a getPage object which is deferred.
    """
    u = self.uri + self._resource['showAuthUser']
    m = 'GET'
    n = self.username
    p = self.password
    b = base64.encodestring('{0}:{1}'.format(n, p)) 
    h = {'Authorization': 'Basic ' + b.strip()}
    return self._getPage(u, m, h)

有沒有辦法在 h 之后找到本地 scope 中所有變量的值?

你可以使用locals() function

暫無
暫無

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

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