how to convert sys.argv strings into list

I am parsing long urls through sys.argv

format parsing is : "url1 ", "url2", "url3"

and output values trying to convert into list but get results like

url1, url2, url3

parsing urls :

 "https://www.amazon.com/sp?_encoding=UTF8&asin=B00ZGCKLE2&isAmazonFulfilled=0&isCBA=&marketplaceID=ATVPDKIKX0DER&orderID=&seller=A6T9C2PUZSUPW&tab=&vasStoreID=","https://www.amazon.com/sp?_encoding=UTF8&asin=B00ZGCKLE2&isAmazonFulfilled=0&isCBA=&marketplaceID=ATVPDKIKX0DER&orderID=&seller=A1916U364TPZBZ&tab=&vasStoreID="

output is, not valid list

['https://www.amazon.com/sp?_encoding=UTF8&asin=B00ZGCKLE2&isAmazonFulfilled=0&isCBA=&marketplaceID=ATVPDKIKX0DER&orderID=&seller=A6T9C2PUZSUPW&tab=&vasStoreID=,https://www.amazon.com/sp?_encoding=UTF8&asin=B00ZGCKLE2&isAmazonFulfilled=0&isCBA=&marketplaceID=ATVPDKIKX0DER&orderID=&seller=A1916U364TPZBZ&tab=&vasStoreID=']

import sys

test = sys.argv[1]

print([test])

parsing command

 python test.py  "https://www.amazon.com/sp?_encoding=UTF8&asin=B00ZGCKLE2&isAmazonFulfilled=0&isCBA=&marketplaceID=ATVPDKIKX0DER&orderID=&seller=A6T9C2PUZSUPW&tab=&vasStoreID=","https://www.amazon.com/sp?_encoding=UTF8&asin=B00ZGCKLE2&isAmazonFulfilled=0&isCBA=&marketplaceID=ATVPDKIKX0DER&orderID=&seller=A1916U364TPZBZ&tab=&vasStoreID="

1 answer

  • answered 2019-07-17 23:42 Gwang-Jin Kim

    import sys
    
    test = sys.argv[1:] # you want all arguments so slice to the end, 
    # test is then already a list
    
    print(test) # so no need to pack `test` into a list here, because it IS a list
    

    Call it then like this

     python test.py  "https://www.amazon.com/sp?_encoding=UTF8&asin=B00ZGCKLE2&isAmazonFulfilled=0&isCBA=&marketplaceID=ATVPDKIKX0DER&orderID=&seller=A6T9C2PUZSUPW&tab=&vasStoreID=" "https://www.amazon.com/sp?_encoding=UTF8&asin=B00ZGCKLE2&isAmazonFulfilled=0&isCBA=&marketplaceID=ATVPDKIKX0DER&orderID=&seller=A1916U364TPZBZ&tab=&vasStoreID="