[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

New to working with APIs, any good tutorials/books/guides?

On Fri, 21 Feb 2014 12:12:00 -0800, ApathyBear wrote:

> Thanks, I think I have an understanding of what they are, but now am
> still a little confused on how one goes about using it: how am I
> supposed to know how to use an API in python? 

*scratches head*

Er, first you learn how to program in Python, then you read the API 
documentation and do what it says. If the documentation says that the 
function requires a single string argument, then you give the function a 
single string argument.

I suspect that either your question is much more subtle and complicated 
than your actual words allow, or you're making things much, much, much 
more complicated than they actually are. In an earlier post, you said you 
had some experience programming in Python. If your code works, then you 
know how to use the APIs of the functions and libraries that you used.

Here I am using the API for the len() function:

alist = [1, 2, 3]
number_of_items = len(alist)

That's all. Easy, wasn't it? I'm using the API for the len() function.

If you were asking for help with some *specific* API ("I don't understand 
the multiprocessing module!"), that I could get. Some APIs are 
complicated, or badly designed, or badly written, or require advanced 
understanding. But APIs *in general* can be as simple as len().

> or in any other language
> for that matter? If an API is defining rules in C, is all hope lost for
> trying to use it in python?

If an API is defined for a C library or function, then, no, you can't use 
it in Python, or Lisp, or Ruby, just as you can't use a Lisp function in 
C or Forth or Pascal. Not unless one or the other language makes special 
provision to allow such cross-language communication.

It might be better for you to give us concrete examples of what you don't 
understand, rather than to continue talking in vague generalities.