[Tutor] There's a Programmer in Me

eryksun eryksun at gmail.com
Wed Feb 27 02:09:11 CET 2013


On Tue, Feb 26, 2013 at 7:49 PM, eryksun <eryksun at gmail.com> wrote:
>
> You can use inspect.getsource(obj) if obj is a module, class, method,
> function, traceback, frame, or code that has a source file (e.g.
> __file__, co_filename) and is defined normally (e.g. class, def):
>
>     >>> import inspect
>     >>> def printsrc(obj): print inspect.getsource(obj)

You ca also use a pager (uses "less" if available; "more" on Windows):

    >>> import inspect, pydoc
    >>> def showsrc(obj): pydoc.getpager()(inspect.getsource(obj))
    ...
    >>> showsrc(inspect)


More information about the Tutor mailing list