Reputation:
My script is taking the first argument as shown in the input below and I am trying to create a list out of it but incorrectly as shown in output, can anyone provide inputs on how to fix this?
projects = sys.argv[1]
ProjectList = list(projects)
INPUT:-
python script.py platform/system/bt,platform/packages/apps/Bluetooth,platform/vendor/qcom-proprietary/ship/bt/hci_qcomm_init
output:
['p', 'l', 'a', 't', 'f', 'o', 'r', 'm', '/', 's', 'y', 's', 't', 'e', 'm', '/', 'b', 't', ',', 'p', 'l', 'a', 't', 'f', 'o', 'r', 'm', '/', 'p', 'a', 'c', 'k', 'a', 'g', 'e', 's', '/', 'a', 'p', 'p', 's', '/', 'B', 'l', 'u', 'e', 't', 'o', 'o', 't', 'h', ',', 'p', 'l', 'a', 't', 'f', 'o', 'r', 'm', '/', 'v', 'e', 'n', 'd', 'o', 'r', '/', 'q', 'c', 'o', 'm', '-', 'p', 'r', 'o', 'p', 'r', 'i', 'e', 't', 'a', 'r', 'y', '/', 's', 'h', 'i', 'p', '/', 'b', 't', '/', 'h', 'c', 'i', '_', 'q', 'c', 'o', 'm', 'm', '_', 'i', 'n', 'i', 't']
Upvotes: 0
Views: 1648
Reputation: 492
Python has a built-in split
method that takes a string and splits it into a list, splitting into new elements at specific delimiters. All you have to do is:
ProjectsList = projects.split(",")
You specify the delimiter within the parenthesis when you call split, in this case, a comma.
Upvotes: 0
Reputation: 566
You can call split method on project and assign it to a new variable.
ProjectList = project.split(',')
Upvotes: 0
Reputation: 79
You can split the string by using a delimiter see below:
projects = sys.argv[1]
ProjectList = projects.split(",")
Upvotes: 0
Reputation: 483
dont use list. it's better if you got with split()
ProjectList = projects.split(',')
Upvotes: 0