osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Basic python question


You could use:

>>> x, y = set(output.split())

On Thu, Oct 3, 2019 at 11:44 AM Jagga Soorma <jagga13 at gmail.com> wrote:

> Hello,
>
> I am new to python and trying to do some basic things with python.  I
> am writing a script that runs a df command and I need parts of that
> output saved in 2 different variables.  Is this something that can be
> done?  I can do this by running multiple df commands but would prefer
> to make only one call:
>
> --
> inode_cmd = "/bin/df --output=pcent,ipcent /var| grep -v Use | tr '%' ' '"
> output  = subprocess.check_output( inode_cmd,
> stderr=subprocess.STDOUT, shell=True )
> --
>
> But this would end up giving me the following:
>
> #df --output=pcent,ipcent /var | grep -v Use | tr '%' ' '
>    5   1
>
> I would like variable x to be 5 and variable y to be 1.  Is there a
> easier way to do this?
>
> Thanks in advance for your guidance.
> --
> https://mail.python.org/mailman/listinfo/python-list
>