[Tutor] SyntaxError: can't assign to literal while using ""blkid -o export %s | grep 'TYPE' | cut -d"=" -f3" % (fs)" using subprocess module in Python

Chris Angelico rosuav at gmail.com
Mon Nov 12 08:56:25 EST 2018


On Mon, Nov 12, 2018 at 11:20 PM Anssi Saari <as at sci.fi> wrote:
>
> Chris Angelico <rosuav at gmail.com> writes:
>
> > On Fri, Nov 9, 2018 at 11:11 PM Anssi Saari <as at sci.fi> wrote:
> >>
> >> Chris Angelico <rosuav at gmail.com> writes:
> >>
> >> > No helper needed. Safe against command injection. Uses the known
> >> > format of the command's output; if you want other information as well
> >> > as the type, you could get that too.
> >>
> >> Can someone let me in on this secret helper module? Doesn't seem to
> >> match the helper module in PyPI at least.
> >>
> >
> > What helper?
>
> Helper module used in the original post. I assumed you know what it is
> since you declared it's not needed.

Oh! I see what you mean. I wasn't referring to an entire module, just
a helper *function*. Look at the OP's code at this function:

def execute_cmd_output_string(self, cmd, enable_shell=False):

This is a function whose sole purpose is to make it easier to write
other functions. That's what's often referred to as a "helper
function". (It's also dangerously written, as it turns other failures
into AssertionError.) By simplifying the code and removing the need
for this helper, we can make it more consistent with the rest of the
Python ecosystem, less buggy [1], and probably easier to read.

ChrisA

[1] It's generally true that a programmer's bugs-per-lines-of-code
metric is fairly stable, so having less code usually means less bugs.
Not certain by any means, but consider: non-code cannot have bugs in
it, and code usually does. It's a good rule of thumb.



More information about the Python-list mailing list