![](/img/trans.png)
[英]Less-than sign in python parameter docstring not showing up in PyCharm
[英]Python Docstring Comments, Greater Than and Less Than Symbols Not Showing
我正在使用文檔字符串注釋 Python 代碼。 注意,這只是一個例子,
def credit_bonus(self, num_purchases: int, total_spend: float)->int:
'''
Calculates eligible and additional credit bonus for a customer, compared to previous
yearly spends, and number of previous purchases.
Additional credit ranking of 2, if current number of purchases > previous purchaces,
and current spend >= 95% previous spend.
Return: customer's credit ranking
'''
....
return credit_rank
當顯示此函數的注釋時,在 VSCode 中,將鼠標懸停在調用它的另一個模塊中的此函數上時,不顯示大於號。 我嘗試了各種轉義字符, >
,到目前為止沒有任何效果。
是否可以在 Python 文檔字符串中顯示 < 和 >?
另外,我知道這不是表演障礙,也不是命令式,只是一個小小的方便,最終會打字,大於,而不是。
謝謝和問候,新澤西州
為函數/方法 DocStrings 工作,而不是為類工作。 自發布以來,我仍在 DocStrings 中鍵入 < 和 >,並且我注意到它(現在?)在哪里起作用,哪里不起作用。 首先是一些規格;
我確實為函數或方法工作,
def __new_connection(self)->sqlite3.Connection:
'''
__new_connection(self)`->`sqlite3.Connection:\n
create a new connection using a connection string, time out, and isolation level settings.\n
return:
sqlite3.Connection.
'''
return sqlite3.connect(database=self.__con_str, timeout=self.__timeout, isolation_level=None, uri=True)
在>
或在本例中->
周圍鍵入尖引號或反引號,將顯示 < 和 > 符號,當 DocString 顯示為方法描述時。
但
對於類文檔字符串,它不起作用。
class Broker:
'''
class wrapper for sqlite3 database objects and operations.\n
transaction type: auto-commit.\n
database type: file system database. not in-memory (:memory:)
isolation level is set to None, i.e. auto-commit, cache is private.
methods:\n
__new_connection(self)->sqlite3.Connection
creates a new sqlite3 connection object
__cursor_execute(self, conn: sqlite3.Connection, sqlCmd: str, params: tuple=())->sqlite3.Cursor
creates a cursor object, execute a parameterised sql statement
'''
無論在 < 或 > 周圍放置什么符號或標記,都不起作用。
如果我找到 DocStrings 類的解決方法,我將再次發布,假設它不起作用(仍然),如果我這樣做了。
謝謝和問候,新澤西州
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.