作者abc95007 (别理我)
看板Python
标题[问题] class 里的变数判断型态?
时间Sat Mar 23 21:08:18 2019
请问例如
class Data():
def __init__(self, df):
self.df = df
print(self.df.columns)
例如进来的变数是 pd.DataFrame
但 python 不用宣告变数
请问如何让 IDE 知道 self.df 是 DataFrame 型态
只是想说能让 IDE 按 tab 自动去补完剩下的字
谢谢~
--
※ 发信站: 批踢踢实业坊(ptt.cc), 来自: 220.134.105.199
※ 文章网址: https://webptt.com/cn.aspx?n=bbs/Python/M.1553346502.A.ACC.html
1F:推 lemon651: 第一个是你缩排错了,第二个你可以试试在变数後宣告type 03/24 09:05
2F:推 sean50301: 我用vscode会有XD ipython也是有这个功能的 03/24 13:57
3F:推 ScottOAO: type annotation 加上冒号型态 03/25 13:21
4F:推 ok963963ok: 如果你用pycharm 可以参考我的文章 03/25 16:46
6F:→ froce: 没记错的话,3.5版之後就可以用type hint 03/26 07:31
7F:→ froce: 之前你可以用assert (type() is )去做 03/26 07:33
8F:推 froce: 看错,以为是单纯的判断类型 03/26 07:36
9F:→ froce: 不过vs code现在的确可以透过type hint去提示你变数的类型 03/26 07:37
10F:→ froce: 了 03/26 07:37