Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a Python equivalent of R's str(), returning only the structure of an object?

Tags:

python

In Python, help(functionName) and functionName? return all documentation for a given function, which is often too much text on the command line. Is there a way to return only the input parameters?

R's str() does this, and I use it all the time.

like image 490
rsoren Avatar asked Oct 18 '25 15:10

rsoren


1 Answers

The closest thing in Python would probably be to create a function based off of inspect.getargspec, possibly via inspect.formatargspec.

import inspect

def rstr(func):
    return inspect.formatargspec(*inspect.getargspec(func))

This gives you an output like this:

>>> def foo(a, b=1): pass
...
>>> rstr(foo)
'(a, b=1)'
like image 175
Amber Avatar answered Oct 21 '25 03:10

Amber