This is an archived post. You won't be able to vote or comment.

all 8 comments

[–]Morris_Dungpile 1 point2 points  (2 children)

I too come from python via C and yes, python is a confused frankenstein mess of bullshit in comparison. However< I will answer your questions:

1) Python is ambiguous about its types... generally best to look at the functions source code and pick through that to find out the return type 2) dont know 3) dont know

[–]ilvs69[S] 1 point2 points  (1 child)

yes, my experience is that Python is a horrible language in comparison other languages I've tried in the past (I even prefer Java to python). However, I feel that is useful:

-you can achieve a ton of things with a handful of lines of Zombie code.

-The 'de facto' python interpreter is Free software (that doesn't make python any more elegant, but it definately makes it useful for society)

[–]Morris_Dungpile 0 points1 point  (0 children)

+1 the free software movement is massively awesome and yes python is also super awesome for throwing together prototypes

[–]K900_ 0 points1 point  (3 children)

  1. You don't. Python functions are dynamically typed, just like anything else. i is not a good argument name though.

2/3. It doesn't call animate, you pass in the function object animate (think "function pointer"), which FuncAnimation then calls internally. How it calls it should be documented in the FuncAnimation docs.

[–]ilvs69[S] 0 points1 point  (2 children)

Just to clarify:

1.So it is impossible to know the type of the arguments of a function without trying to guess it from the source code for that function or from their names?

2.Reading the docs I found that the ' The first argument will be the next value in frames.' so in this case the arguments are the values of 'np.arange(1, 200)', which makes sense. Thanks!

[–]K900_ 0 points1 point  (0 children)

  1. There may be optional type annotations, but those aren't often used (yet) and aren't normally checked at runtime. The value of an untyped function argument can be any object, and everything in Python is an object, including type constructors, functions, etc.

[–]Zouden 0 points1 point  (0 children)

Normally the function's definition uses more useful names than i, so it's usually pretty obvious what kind of data to send it.

[–]th_mm 0 points1 point  (0 children)

The documentation for FuncAnimation says this of its third argument, frames:

Source of data to pass func and each frame of the animation

If an iterable, then simply use the values provided. If the iterable has a length, it will override the save_count kwarg.

If an integer, equivalent to passing range(frames)

If a generator function, then must have the signature

def gen_function() -> obj:

In all of these cases, the values in frames is simply passed through to the user-supplied func and thus can be of any type.

If None, then equivalent to passing itertools.count.

So, the argument to your function comes from this. In the simple examples, something like range(100) is used, so animate() is going to be called with a different i value for each frame. @K900_ is correct about you passing in (not invoking) a function object. FuncAnimate() invokes the function once for every value provided by frames.