B
B
beduin012018-07-05 13:13:01
Python
beduin01, 2018-07-05 13:13:01

How to get rid of the quotes around the list?

import argparse

clients_ids = []
parser = argparse.ArgumentParser()
parser.add_argument('-i', '--ids', action='store', nargs='+', dest='cids', help='client_ids for sending. Example: -i=1,2,3')
arguments = parser.parse_args()

clients_ids = arguments.cids
print(clients_ids)
print(type(clients_ids))

The problem is that the result is enclosed in quotes:
python3 app.py -i=155,2,3
['155,2,3']
<class 'list'>

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Roman Telichkin, 2018-07-05
@Telichkin

You are not passing 3 different values ​​for the -i argument, but one. To pass all three, you need to do this:

python3 app.py -i 155 2 3
['155', '2', '3']
<class 'list'>

S
sim3x, 2018-07-05
@sim3x

clients_ids = arguments.cids[0].split(',')

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question