#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0

    Reading builtin python modules


    I dont understand how to read the code in the builtin python modules. I know how to find out whats in a module for example,

    import os;

    dir(os)
    But when I try to look for example for the function listdir I cannot find a def listdir to read what it actually does.
  2. #2
  3. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,701
    Rep Power
    480
    The source for os.listdir is almost certainly written in c. Python would load it from a shared object or dynamic link library. If you really want it, download the python source and hunt for it.

    ...Trying my advice...
    I think it starts with this line in file posixmodule.c.

    posix_listdir(PyObject *self, PyObject *args, PyObject *kwargs)
    [code]Code tags[/code] are essential for python code and Makefiles!
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by b49P23TIvg
    The source for os.listdir is almost certainly written in c. Python would load it from a shared object or dynamic link library. If you really want it, download the python source and hunt for it.

    ...Trying my advice...
    I think it starts with this line in file posixmodule.c.

    posix_listdir(PyObject *self, PyObject *args, PyObject *kwargs)
    Ok thank you for the response but I still dont quite follow. OS.py is written in python right? so when i import os im importing os.py, why then can i not find the functions listed inside os.py that i can see when i do a dir(os)
  6. #4
  7. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,701
    Rep Power
    480
    An os.py on my system:
    /usr/lib/python2.7/os.py


    Read this manual.
    [code]Code tags[/code] are essential for python code and Makefiles!
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2012
    Posts
    4
    Rep Power
    0
    Originally Posted by b49P23TIvg
    An os.py on my system:
    /usr/lib/python2.7/os.py


    manual.
    That goes a little over my head at this stage in my learning python. Are you basically saying that the functions arent in os.py but os.py loads some c code that includes the os.blar functions?
  10. #6
  11. Contributing User
    Devshed Demi-God (4500 - 4999 posts)

    Join Date
    Aug 2011
    Posts
    4,701
    Rep Power
    480
    Yes.
    [code]Code tags[/code] are essential for python code and Makefiles!

IMN logo majestic logo threadwatch logo seochat tools logo