Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lists as arguments
#2
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...:

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).
Reply


Messages In This Thread
lists as arguments - by vinci - Oct-26-2020, 04:21 PM
RE: lists as arguments - by bowlofred - Oct-26-2020, 05:34 PM
RE: lists as arguments - by deanhystad - Oct-26-2020, 05:44 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Split dict of lists into smaller dicts of lists. pcs3rd 3 2,443 Sep-19-2020, 09:12 AM
Last Post: ibreeden
  sort lists of lists with multiple criteria: similar values need to be treated equal stillsen 2 3,319 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 3,907 Mar-02-2017, 10:23 PM
Last Post: zivoni

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020