Giter Site home page Giter Site logo

pombredanne / python-inspector Goto Github PK

View Code? Open in Web Editor NEW

This project forked from sebdah/python-inspector

0.0 1.0 0.0 80 KB

Used to track down which Python module and script that called your method / function. It will show you the exact Python file, line number and the actual line that made the call. The module is plug'n'playable, just import it and place a non-interfering hook in your code.

Home Page: http://sebdah.github.com/python-inspector/

License: Other

python-inspector's Introduction

python-inspector

This module helps you to track down which Python method that called your method. It can be helpful when debugging code in some situations. All you need to do is to import the module to your project and call inspector.trace() (and catch the output rows).

Installation

The python-inspector is available trough pip, simple run

pip install python-inspector

Requirements

Python version >2.5 and <3.0

Example usage

Here's a simple example usage of the inspector

#!/usr/bin/env python

"""
Testing the Python call inspector
"""
import sys
import inspector

def func2():
    """
    Example method
    """
    # This is the method you want to debug

    # Your code here

    print 'TRACE OUTPUT:'
    for log_row in inspector.trace():
        print log_row

    # More code
    
    return True

def func1():
    """
    Example method
    """
    return func2()

def call_me():
    """
    Call this function to test
    """
    return func1()

call_me()

sys.exit(0)

In this example we debug func2() using the inspector. The output generated will look like this:

TRACE OUTPUT:
t.py:29 in method func1
	return func2()
t.py:35 in method call_me
	return func1()
t.py:37 in method <module>
	call_me()

Documentation for inspector

The inspector module is really simple and does only contain one function, trace.

Function trace

The docstring explains this pretty well.

Trace the current method call and return an array of log lines

Kwargs:
    depth (int)::
        How many deep do you want to dig, i.e. how many callers to show.
        Set to 0 to get all calls. (default 0)
    one_line_response (bool)::
        Write the response log lines on one row (default False)
    basename_only::
        Return the filename without path (default False)

Returns:
    List of strings (loglines), [str, str..]

Return data

The method returns a list of log lines (strings). I.e. [str, str ...]

Release notes

0.2.0 (2013-01-07)

  • Made the script available under Apache license 2.0
  • Added python-inspector to pip

0.1.0 (2012-12-05)

  • Initial release

python-inspector's People

Contributors

sebdah avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.