osdir.com


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

Basic python question


Thanks again Aldwin.  This seems to work, guess it is the set that is
flipping the numbers:

x,y = (output.split())

Much appreciated!

On Wed, Oct 2, 2019 at 9:19 PM Aldwin Pollefeyt
<aldwinaldwindev at gmail.com> wrote:
>
> Seems to work also:
>
> >>> [x,y] = output.split()
>
> On Thu, Oct 3, 2019 at 12:17 PM Aldwin Pollefeyt <aldwinaldwindev at gmail.com> wrote:
>>
>> Oh, sorry .. please try this:
>>
>> >>> x,y = tuple(output.split())
>>
>> On Thu, Oct 3, 2019 at 12:11 PM Jagga Soorma <jagga13 at gmail.com> wrote:
>>>
>>> Thanks Aldwin that helps but it looks like it is reversing the numbers
>>> for some reason:
>>>
>>> the df command returns the following:
>>> 7  2
>>>
>>> I used your example and did:
>>> x,y = set(output.split())
>>>
>>> My assumption would be that x should be 7 and y should be 2.  However,
>>> when I print x and y it seems to be reversed (x is 2 and y is 7).  Am
>>> I missing something?
>>>
>>> Thanks
>>>
>>> On Wed, Oct 2, 2019 at 8:49 PM Aldwin Pollefeyt
>>> <aldwinaldwindev at gmail.com> wrote:
>>> >
>>> > 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