The HTTP response header for 'packages_list' returns the following, which is a list looking string. How do i convert this to an actual list? I have tried typecasting the string as a list which didn't work. I am not keen on doing find and replace or strip. Once I have the list I am creating a windows forms with buttons with text for each of the items in list. Any help is appreciated
I am using IronPython 2.6 (yes, I know its old but cant move away for backward compatibility reasons)
['Admin', 'MMX_G10_Asia', 'MMX_G10_London', 'MMX_G10_Readonly', 'MMX_Credit_Readonly', 'MMX_Govies_ReadOnly']
httpConn = httplib.HTTPConnection(base_server_url)
httpConn.request("POST", urlparser.path, params)
response = httpConn.getresponse()
headers = dict(response.getheaders())
print headers['packages_list']
The simplest approach, IMHO, would be to use literal_eval:
>>> s = "['Admin', 'MMX_G10_Asia', 'MMX_G10_London', 'MMX_G10_Readonly', 'MMX_Credit_Readonly', 'MMX_Govies_ReadOnly']"
>>> s
"['Admin', 'MMX_G10_Asia', 'MMX_G10_London', 'MMX_G10_Readonly', 'MMX_Credit_Readonly', 'MMX_Govies_ReadOnly']"
>>> from ast import literal_eval
>>> literal_eval(s)
['Admin', 'MMX_G10_Asia', 'MMX_G10_London', 'MMX_G10_Readonly', 'MMX_Credit_Readonly', 'MMX_Govies_ReadOnly']
You can to check if the string is a valid python type
>>> import ast
>>> s = "['Admin', 'MMX_G10_Asia', 'MMX_G10_London', 'MMX_G10_Readonly', 'MMX_Credit_Readonly', 'MMX_Govies_ReadOnly']"
>>> ast.literal_eval(s)
['Admin', 'MMX_G10_Asia', 'MMX_G10_London', 'MMX_G10_Readonly', 'MMX_Credit_Readonly', 'MMX_Govies_ReadOnly']
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With