Quickies

[categories] [index] [all (531)] [latest]

Python
  1. import inspect
    
    def f():
        a = 1 + 2
        return a
    
    s = inspect.getsource(f)
    print s
    
    """    
    def f():
        a = 1 + 2
        return a
    """
    
    lines, start = inspect.getsourcelines(f)
    print lines
    
    """
    ['def f():n', '    a = 1 + 2n', '    return an']
    """