python中__doc__、__name__、__file__的使用

各自的作用:

doc:獲取到註釋內容

name:獲取到函數的名稱

file:獲取到當前的文件路徑(獲取模塊路徑)

示例代碼

#! /usr/bin/env python
# -*- coding: utf-8 -*-
from win32gui import *
import timeit
titles = set()
def foo(hwnd,mouse):
    """
    我是foo的註釋
    """
    if IsWindow(hwnd) and IsWindowEnabled(hwnd) and IsWindowVisible(hwnd):
        titles.add(GetWindowText(hwnd))

print("timeit.__doc__:",timeit.__doc__)
print("timeit.__name__:",timeit.__name__)
print("timeit.__file__:",timeit.__file__)

print("foo.__doc__:",foo.__doc__)
print("foo.__name__:",foo.__name__)
print("__file__:",__file__)

輸出結果

timeit.__doc__: Tool for measuring execution time of small code snippets.

This module avoids a number of common traps for measuring execution
times.  See also Tim Peters' introduction to the Algorithms chapter in
the Python Cookbook, published by O'Reilly.

Library usage: see the
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章