-3

What is the optimal way to get documentation about a specific function in Python? I am trying to download stock price data such that I can view it in my Spyder IDE.

The function I am interested in is:

ystockquote.get_historical_prices

How do I know how many inputs the function takes, the types of inputs it accepts, and the date format for example?

Remi Guan
  • 21,506
  • 17
  • 64
  • 87
jessica
  • 1,325
  • 2
  • 21
  • 35
  • 2
    Did you try using Python's help function on the function you need help with? You can use the help method in interactive mode or you can print out the results if you're running in an IDE. – Shaymin Gratitude Feb 02 '16 at 01:20
  • I am sorry I am new. How do I use Python's help function? – jessica Feb 02 '16 at 01:27
  • 2
    It's a method. You just give help parameters, such as a function: help(ystockquote.get_historical_prices). You can also try googling: https://pypi.python.org/pypi/ystockquote – Shaymin Gratitude Feb 02 '16 at 01:29
  • @Shaymin Actually, it's an instance of the site._Helper class. – zondo Feb 02 '16 at 02:42

1 Answers1

1

Just finding documentation

I suspect this question was super-downvoted because the obvious answer is to look at the documentation. It depends where your function came from, but googling is typically a good way to find it (I found the class here in a few seconds of googling).

It is also very trivialy to just check the source code

In order to import a function, you need to know where the source file it comes from is; open that file: in python, docstrings are what generate the documentation and can be found in triple-quotes beneath the function declaration. The arguments can be inferred from the function signature, but because python is dynamically typed, any type "requirements" are just suggestions. Some good documenters will provide the optimal types, too.

While "how do I google for documentation" is not a suitable question, the question of how to dynamically infer documentation is more reasonable. The answer is

  1. The help function, built in here
  2. The file __doc__ accessible on any python object, as a string
  3. Using inspection

The question is even more reasonable if you are working with python extensions, like from external packages. I don't if the package you specifically asked about has any of those, but they can be tricky to work with if the authors haven't defined docstrings in the module. The problem is that in these cases, the typing can be rigidly inforced. There is no great way to get the tpye requirements in this case, as inspection will fail. If you can get at the source code, though, (perhaps by googling), this is where the documentation would be provided

Community
  • 1
  • 1
en_Knight
  • 5,301
  • 2
  • 26
  • 46