Separate string Python, independent parameters

0

First of all thank you for the attention, and on the other hand I do not think it's so difficult what I'm trying to do, only that I've been stuck for 2 days and I do not know what to do.

I have a software to which a script is added. This software passes 2 parameters

sys.argv [1] and sys.argv [2]

But the software passes the 2 parameters as a string.

EDIT:

  

How can I separate these 2 parameters to interpret them as   independent parameters?

My software uses the variable $ MOST_REPEATED $ with this format: 192.168.1.1 1.2.3.4 and I need you to take it for each of them.

It is worth mentioning that I do not have access to the program code that stores this data in the variable $ MOST_REPEATED $

 host = sys.argv [1]
 ip_src = sys.argv [2]

It's done in python.

    
asked by Zero22 21.09.2017 в 16:11
source

1 answer

0

If you do not have a way to modify how the parameters are sent, what you could do is treat them according to how you receive them. For your comments, an application invokes your Script in the following way:

python script.py "parametro1 parametro2"

The Script will only interpret that it is receiving a single parameter, in which case you should do the following:

host, ip_src  = sys.argv[1].split()

We retrieve a single parameter that represents the string "parametro1 parametro2" and using the method split() , we separated in two from the blank space, which returns a list that we assign immediately to our two variables.

    
answered by 21.09.2017 / 17:13
source