2

I have used type() function in my program...

I just want to know how does Python implement this? Or where could I find the source code file that implement this function?

durron597
  • 31,968
  • 17
  • 99
  • 158
Rahul Gupta
  • 227
  • 1
  • 3
  • 7
  • 3
    `type` is not only a function, it is the base class for all metaclasses of new-style classes. See [Python's data model](http://docs.python.org/reference/datamodel.html) for further reading. – ephemient Apr 19 '12 at 04:11

2 Answers2

13

The type() function is implemented in C. Here's a link to the source: http://hg.python.org/cpython/file/0f837071fd97/Objects/typeobject.c

Raymond Hettinger
  • 216,523
  • 63
  • 388
  • 485
2

In general

import multiprocessing
multiprocessing.__path__
multiprocessing.__file__

__path__ yields location of the library __file__ yields complete path of the file.

If above didn't work, you need to look into python development source code.

Regarding type source code, Raymond Hettinger's answer is correct.

Kracekumar
  • 19,457
  • 10
  • 47
  • 56
  • 2
    No. `type`, like other members of `__builtin__`, are built into the Python interpreter, and are not a separate library. – ephemient Apr 19 '12 at 04:28
  • @ephemient: I din know this, I was under assumption whenever interpreter loads, builtin funcs are imported to namespace, so all builtins reside in /some/path/for/builtins/*.so – Kracekumar Apr 19 '12 at 04:35