13

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 .

1
  • 1
    If you're using *nix, this command pattern is quite useful to find files with a portion of a string (such as "sys") in them: find ./* | grep -i sys Commented Jun 20, 2011 at 10:44

3 Answers 3

13

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.

Sign up to request clarification or add additional context in comments.

2 Comments

Cool. Now, where are the pydocs source for this module, which I suppose is what I was really looking for.
@MichaelScheper : are these the docs, perhaps? docs.python.org/3/library/sys.html
7
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.

1 Comment

This is useful because it works for other modules, like unittest that I was looking for today.
2

It's in Python/Python/sysmodule.c.

1 Comment

couldn't find it in Python 3.11 version

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.