2016-05-19 42 views
1

我正在使用pycharm 2016.1。pycharm快速文檔(CTRL + Q)不加載本地記錄文件

我有一個功能,記錄如下:

def extract_filename(filepath, ext=None): 
    """ 
    This function returns the filename from a complete filepath including its extension. 
    If ext is set to an extension it is removed from the filename. 


    Parameters 
    ---------- 
    filepath : string 
    ext : string 

    Returns 
    ------- 
    string 
    """ 

    if ext[0] != ".": 
     ext = "." + ext 

    filename = filepath.split("/")[-1] 
    if ext is not None: 
     filename = filename.split(ext)[0] 

    return filename 

我期待,一旦該文件是在地方,我能夠看到它時,我按CTRL彈出的快捷文檔窗口+ Q.但是,情況並非如此。該窗口只顯示類型推斷:

def extract_filename(filepath, ext=None) Inferred type: (filepath: Union[str, unicode], ext: Union[str, unicode]) -> Union[str, unicode] 

我在這裏錯過了什麼?我認爲通過記錄我的功能,其描述和參數將顯示格式良好。

我發現這個職位:Documenting Python parameters in docstring using PyCharm。但是希望使用NumPy格式來編寫文檔。

謝謝!

回答

2

看起來好像每個人對Docstrings都有不同的標準,並且給出了PEP-257中的文檔,我可以看到爲什麼你會以這種方式對事物進行格式化。 PyCharm喜歡這樣的:

def function(arg1, arg2, ..., argn): 
    """ 

    Description of the function and what it returns in an active tone. 

    :param arg1: What the argument represents. 
    ... 
    :param argn: What the argument represents. 

    :return: The meaning of the return value 
    """ 

,當應用到你的代碼,看起來像:

def extract_filename(filepath, ext=None): 
    """ 

    Return the file name from a complete file path including its extension. 
    If ext is set to an extension, remove it from the file name. 

    :param filepath: The full path to the file in question. 
    :param ext: The extension for the file. 

    :return: The filename from filepath including its extension. 
    """ 
    if ext[0] != ".": 
     ext = "." + ext 

    filename = filepath.split("/")[-1] 
    if ext is not None: 
     filename = filename.split(ext)[0] 

    return filename 
+0

非常感謝!有什麼方法可以改變pycharm的期望嗎?另外,使用你發佈的格式,有什麼方法可以指出參數的類型和返回值嗎? –

+0

他們給出了關於[這裏]的詳細信息(https://www.jetbrains.com/help/pycharm/2016.1/using-docstrings-to-specify-types.html),儘管我不確定你會如何改變它期待..我有自己的慣例,一般來說,你仍然可以看到任何你輸入的常規文本,所以試着弄點兒。 – chrislessard