Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
lists as arguments
#3
Functions do no expect arguments in square brackets. A function may expect a list as an argument.
def reverse_list(src_list):
    return [src_list[a] for a in range(len(src_list)-1, -1, -1)]

x = reverse_list([1, 2, 3, 4, 5])
print(x)
print(reverse_list(x))
The function reverse_list() expects a list. [1, 2, 3, 4, 5] is a list. x is also a list.

When I type help(subprocess.run) I get this:
Quote:Help on function run in module subprocess:

run(*popenargs, input=None, capture_output=False, timeout=None, check=False, **kwargs)
Run command with arguments and return a CompletedProcess instance.

The returned instance will have attributes args, returncode, stdout and
stderr. By default, stdout and stderr are not captured, and those attributes
will be None. Pass stdout=PIPE and/or stderr=PIPE in order to capture them.

If check is True and the exit code was non-zero, it raises a
CalledProcessError. The CalledProcessError object will have the return code
in the returncode attribute, and output & stderr attributes if those streams
were captured.

If timeout is given, and the process takes too long, a TimeoutExpired
exception will be raised.

There is an optional argument "input", allowing you to
pass bytes or a string to the subprocess's stdin. If you use this argument
you may not also use the Popen constructor's "stdin" argument, as
it will be used internally.

By default, all communication is in bytes, and therefore any "input" should
be bytes, and the stdout and stderr will be bytes. If in text mode, any
"input" should be a string, and stdout and stderr will be strings decoded
according to locale encoding, or by "encoding" if set. Text mode is
triggered by setting any of text, encoding, errors or universal_newlines.

The other arguments are the same as for the Popen constructor.

If that isn't enough information I look at the python documentation:

https://docs.python.org/3.9/library/subprocess.html

The manual page has this gem:

Quote:args is required for all calls and should be a string, or a sequence of program arguments. Providing a sequence of arguments is generally preferred, as it allows the module to take care of any required escaping and quoting of arguments (e.g. to permit spaces in file names). If passing a single string, either shell must be True (see below) or else the string must simply name the program to be executed without specifying any arguments.
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,312 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,190 Mar-20-2019, 08:01 PM
Last Post: stillsen
  Functions (Arguments Passing,Changing a mutable ,Assignment to Arguments Names) Adelton 2 3,819 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