0

I've written some classes in Python and I have written docstrings for them like this:

class DB:
    def execute_and_return(self, sql):
        """Execute the query and returns the result as a list of list
        Parameters
        ----------
        sql: str
            Your query
        Returns
        -------
        list""

If I want to access the docstring in another class I can simply call DB.execute_and_return.__doc__ and I get the string.

However if I'm interesting to know the name of the parameters (in this case sql) and the type of data (in this case str) is there any built in functions for accessing that?

axel_ande
  • 359
  • 1
  • 4
  • 20

1 Answers1

0

python does not have strict types, so you can never be sure of what type a variable should be unless it is clearly stated in the documentation. but there is a way to find the variable names in python:

import inspect
args = inspect.getargspec(DB.execute_and_return)[0]
AntiMatterDynamite
  • 1,495
  • 7
  • 17