Where are math.py and sys.py?

前端 未结 4 829
孤独总比滥情好
孤独总比滥情好 2020-12-31 07:47

I found all the other modules in Python33/Lib, but I can\'t find these. I\'m sure there are others \"missing\" too, but these are the only ones I\'ve noticed. They work just

相关标签:
4条回答
  • 2020-12-31 08:08

    These modules are not written in Python but in C. You can find them (at least on linux) in a subfolder of the lib-folder called lib-dynload.
    The math module is then in a file math.cpython-33m.so (on windows probably with .dll instead of .so). The cpython-33m part is my python version (3.3).

    0 讨论(0)
  • 2020-12-31 08:09

    The modules like math, time, gc are not written in python and as rightly said in above answers that they are somewhere (written or moduled) within python interpreter. If you import sys and then use sys.builtin_module_names (it gives tuple of module names built into this interpreter). math is one such module in this list. So, we can see that math comes from here and is not separately written in library or any other folder as a python code.

    0 讨论(0)
  • 2020-12-31 08:15

    The math and sys modules are builtins -- for purposes of speed, they're written in C and are directly incorporated into the Python interpreter.

    To get a full list of all builtins, you can run:

    >>> import sys
    >>> sys.builtin_module_names
    

    On my machine, that results in the following list:

    __builtin__
    __main__
    _ast
    _bisect
    _codecs
    _codecs_cn
    _codecs_hk
    _codecs_iso2022
    _codecs_jp
    _codecs_kr
    _codecs_tw
    _collections
    _csv
    _functools
    _heapq
    _hotshot
    _io
    _json
    _locale
    _lsprof
    _md5
    _multibytecodec
    _random
    _sha
    _sha256
    _sha512
    _sre
    _struct
    _subprocess
    _symtable
    _warnings
    _weakref
    _winreg
    array
    audioop
    binascii
    cPickle
    cStringIO
    cmath
    datetime
    errno
    exceptions
    future_builtins
    gc
    imageop
    imp
    itertools
    marshal
    math
    mmap
    msvcrt
    nt
    operator
    parser
    signal
    strop
    sys
    thread
    time
    xxsubtype
    zipimport
    zlib
    
    0 讨论(0)
  • 2020-12-31 08:30

    I don't know about math, but sys is a runtime service for the interpretor, and hence always available. Check out this. You'll also find the list of built-ins from this page.

    Also check out this topic, and you could try following links.

    0 讨论(0)
提交回复
热议问题