Python How to read APIs (Python)(PyBrain)

  • Thread starter Thread starter K29
  • Start date Start date
AI Thread Summary
Understanding APIs can be challenging, particularly when dealing with parameters like *args and **kwargs. Many users find that API documentation, such as that provided by PyBrain, often lacks clarity regarding the specifics of these parameters. The documentation may only imply that *args and **kwargs are pointers without detailing their contents or types. To effectively grasp their usage, it is often necessary to read the source code directly, as this can provide clearer insights into how these arguments function within the code. Additionally, consulting more organized sections of the documentation, like the modindex, can be beneficial, although it may still lead back to the same unclear API details. Engaging with community forums, such as Google Groups linked in the documentation, can also be a resource, but responses may not always be prompt. Overall, a combination of reading the code and utilizing available documentation is essential for understanding how to work with variable arguments in Python.
K29
Messages
103
Reaction score
0
I am having trouble getting the hang of understanding APIs. After going through tutorials I find myself wanting to see what parameters I can pass to an object. So I look in the api and I see stuff like *args and **kwargs

e.g.
http://pybrain.org/docs/api/structu...pybrain.structure.networks.FeedForwardNetwork

I've looked everywhere to try and find what those *args consist of, but I'm at a loss. Anyone frequently consult API documentation and know what I should be reading?
 
Technology news on Phys.org
K29 said:
I am having trouble getting the hang of understanding APIs. After going through tutorials I find myself wanting to see what parameters I can pass to an object. So I look in the api and I see stuff like *args and **kwargs

e.g.
http://pybrain.org/docs/api/structu...pybrain.structure.networks.FeedForwardNetwork

I've looked everywhere to try and find what those *args consist of, but I'm at a loss. Anyone frequently consult API documentation and know what I should be reading?
The docs in the link you provided are pretty poor, IMO, as they don't give any information about the arguments of the functions listed, such as what they represent and their types.

About all that one can infer from this page are that arg represents a pointer to something, and that kwargs is a pointer to a pointer to something. In other words, arg holds the address of something, and kwargs holds an address that is the address of something.
 
This looks like something where you will have to find an associated forum and look at the FAQ. And it does not appear to actively maintained. Which is a bad sign. I would start by reading through this page:

http://pybrain.org/docs/modindex.html The documentation appears more sensible there. You can backwards relate the class information down to the API.
 
Even worse, the **args argument to class pybrain.structure.networks.Network(name=None, **args) should have been **kwargs.

Sometimes the only way to see how those extra list arguments (*args) and keyword arguments (**kwargs) are used is to RTFC ("Read The Ffing Code").

This is a dirty little secret to python: You can write functions that take a variable number of positional arguments, and an arbitrary dictionary of keyword arguments. That extra kruft is what these *args and **kwargs are receiving. This approach is often used in constructors of derived classes so that stuff not needed by the derived class but is needed by a base class can be easily collected and passed to the base class constructors.Addendum
See the latter half of section 4.7.2 plus sections 4.7.3 and 4.7.4 in the python tutorial. Link: http://docs.python.org/2/tutorial/controlflow.html#keyword-arguments.
 
Last edited:
Expanding slightly on what D H says, a function taking the arguments (*args,**kwargs) can take any parameters at all. If you run:
Code:
def f(*args,**kwargs):
    print args
    print kwargs

f(1,2,3,x=1,y="n")
you'll find that args is a list containing all of the "bare" parameters ([1,2,3], in this case), and kwargs is a dict containing all of the keyword parameters keyed by the keywords(["x":1,"y":"n"], in this case). So the docs tell you precisely nothing. You'll have to either look at the code or try to talk to someone who knows what they're talking about.

I note that the index page (http://pybrain.org/docs/index.html) links to a Google Group that might be able to help. It requires you to sign up to see, which I haven't done, so I don't know if it's active at all.
 
Thanks for all the help everyone.

I tried the modindex first. But its links into the API. Going up the class tree didnt reveal anything new to me as far as **args go. Well I tried the google group first. It looked somewhat active, but after 12 hours of no response I decided to read the code. To be honest reading the code was simple enough. In fact, there was one place in the API that said something along the lines of "this is not all the methods that are available." Very poor documentation indeed. Fortunately the source is very neat and clearly commented.

Also thanks all for the explanations of **args and **kwargs. I was unaware of that.
 
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...

Similar threads

Replies
3
Views
2K
Replies
10
Views
3K
Replies
11
Views
2K
Replies
3
Views
2K
Replies
4
Views
2K
Replies
3
Views
4K
Replies
3
Views
3K
Back
Top