Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

where is the sys module in python source code?

Tags:

python

module

I have found most python modules in python source directory, under Python/Lib or Python/Modules ,but where is the sys (import sys) module ? I didn't find it .

like image 741
renenglish Avatar asked Jun 20 '11 10:06

renenglish


People also ask

How do I open a Python sys module?

Like all the other modules, the sys module has to be imported with the import statement, i.e. The sys module provides information about constants, functions and methods of the Python interpreter. dir(system) gives a summary of the available constants, functions and methods.

Is SYS included in Python?

The sys module in Python provides various functions and variables that are used to manipulate different parts of the Python runtime environment. It allows operating on the interpreter as it provides access to the variables and functions that interact strongly with the interpreter.

What package is sys in Python?

This module provides access to some variables used or maintained by the interpreter and to functions that interact strongly with the interpreter. It is always available.

How do I find out where a module is located?

You can manually go and check the PYTHONPATH variable contents to find the directories from where these built in modules are being imported. Running "python -v"from the command line tells you what is being imported and from where. This is useful if you want to know the location of built in modules.


2 Answers

The Answer

I find it here: ./Python/sysmodule.c

If you're on Linux or Mac OS X, and in doubt, just try find . -name 'sysmodule.c' in the Python directory.

Other Stuff

The way I found it was by searching for the string "platform" throughout the Python directory (using TextMate), as I've used e.g. sys.platform before from the sys module... something similar can be done with grep and xargs.

Another suggestion could be : for i in ./**/*.c ; do grep -H platform $i ; done

This will loop through all *.c files present in anywhere up the file tree you're currently located at, and search the file for "platform". The -H flag will ensure we get a filename path so we can trace the matches back to the files they are found in.

like image 60
Dan Avatar answered Sep 20 '22 02:09

Dan


import sys
help(sys)

Then you will see something like the following:

Help on built-in module sys:

NAME
    sys

FILE
    (built-in)

In my working environment, sys is built into python itself.

like image 37
Drake Guan Avatar answered Sep 21 '22 02:09

Drake Guan