當前位置:編程學習大全網 - 編程軟體 - 怎樣在Python中查詢相關函數的源代碼

怎樣在Python中查詢相關函數的源代碼

在 python 官網下載 Gzipped source tar ball, 解壓縮後, 會發現 Lib/os.py 文件這行代碼

from posix import *

可是沒有文件叫 posix.py 啊, 到底在那 ? 其實 posix module 是 builtin 的其中壹分子,如下示範:

>>> import sys

>>> print sys.builtin_module_names

(*__builtin__*, *__main__*, *_ast*, *_codecs*, *_sre*, *_symtable*, *_warnings*, *_weakref*, *errno*, *exceptions*, *gc*, *imp*, *marshal*, *posix*, *pwd*, *signal*, *sys*, *thread*, *zipimport*)

>>>

所以要去 Modules 目錄查找 c 代碼, 妳會看見 posixmodule.c, 打開它看見這行代碼:

{"listdir", posix_listdir, METH_VARARGS, posix_listdir__doc__},

再尋找上面所得到的 posix_listdir method, 可以找到 listdir 源代碼:

static PyObject *

posix_listdir(PyObject *self, PyObject *args)

{

/* XXX Should redo this putting the (now four) versions of opendir

in separate files instead of having them all here... */

#if defined(MS_WINDOWS) && !defined(HAVE_OPENDIR)

PyObject *d, *v;

HANDLE hFindFile;

BOOL result;

  • 上一篇:孩子5歲想給報編程班,哪家少兒編程教育培訓機構更好?
  • 下一篇:keil編程數碼管只顯示壹個數字proteus
  • copyright 2024編程學習大全網