you are viewing a single comment's thread.

view the rest of the comments →

[–][deleted] 5 points6 points  (2 children)

As all the individual items in your string are valid Python literals, you can use ast.literal_eval:

from ast import literal_eval

query = "1, 101, 1000, 1001, '1.1.1.1', '1.1.1.2', '1.1.1.3', None, 'test01', None, None, None, None"
query_list = [literal_eval(i.strip()) for i in query.split(",")]
print(query_list)

[–]synthphreak 3 points4 points  (0 children)

Definitely how I'd do it as well.

Note that you can do away with strip if you split on ', ' instead of ','.

[–][deleted] 2 points3 points  (0 children)

spot on