簡體   English   中英

/ help()函數不返回用戶定義函數的文檔字符串

[英]/help() function not return docstring of user-defined function

我嘗試使用python help()函數預覽我創建的函數的文檔字符串,但終端始終提示“ NameError:未定義名稱'functionName'”。

我嘗試將參數傳遞到函數中,但沒有任何幫助。

def coefficients():
    """ Evaluates value of inputs and determines use case for almighty formula function """
    def coefficient_of_xsquared():
        if a == "" or a == 0 or a == " ":
            print (error)
            return a 
        coefficient_of_xsquared()

    def coefficient_of_x(): 
        if b == "" or b == 0 or b == " ":
            print (error)
            return b
        coefficient_of_x()

    def coefficient_of_one():
        if c == "" or c == 0 or c == " ":
            print (error)
            return c
        coefficient_of_one()

預期:評估輸入值並確定全能公式函數的用例

實際:

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name 'coefficients' is not defined

聽起來好像在嘗試調用help時未定義函數。

如果函數是在文件中定義的(例如modulename.py ),則需要modulename.py其導入到交互式解釋器中,然后才能使用它。 如果文件名為MODULENAME.py ,請嘗試使用from MODULENAME import coefficients

暫無
暫無

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

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