Oct-26-2020, 05:34 PM
You can't infer it from the definition unless it contains hints (which are optional). A function can be validly called with an int or a list passed as one of the arguments, but the function may not handle both cases properly.
Generally you will use the documentation for what to pass in.
Let's start with bytes. The help for it shows...:
Okay, so for the single argument call, it wants that argument to be an iterable of ints. A list of ints would be fine (as your example), a bare int would not.
When you look at subprocess, it tells you it wants the same args as Popen. Looking at Popen, it tells us the first argument is:
So this function can take a string (and it will try to parse the string) or a sequence (and it will treat each element as a separate execution argument).
Generally you will use the documentation for what to pass in.
Let's start with bytes. The help for it shows...:
Quote:Help on class bytes in module builtins:
class bytes(object)
| bytes(iterable_of_ints) -> bytes
...
Okay, so for the single argument call, it wants that argument to be an iterable of ints. A list of ints would be fine (as your example), a bare int would not.
When you look at subprocess, it tells you it wants the same args as Popen. Looking at Popen, it tells us the first argument is:
Quote: | Arguments:
| args: A string, or a sequence of program arguments.
So this function can take a string (and it will try to parse the string) or a sequence (and it will treat each element as a separate execution argument).