Converting a string to list for submission to easygui multenterbox
Please help a newbe. I have a string returned from an esygui
multchoicebox that looks like
this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to
this: ['ksals', '', 'alsdkfj', '3', '']
This is so I can submit this to a multchoicebox with 5 fields
--
http://mail.python.org/mailman/listinfo/python-list
Converting a string to list for submission to easygui multenterbox
Please help a newbe. I have a string returned from an esygui
multchoicebox that looks like
this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to
this: ['ksals', '', 'alsdkfj', '3', '']
This is so I can submit this to a multenterbox with 5 fields
--
http://mail.python.org/mailman/listinfo/python-list
Re: Converting a string to list for submission to easygui multenterbox
On May 1, 4:26 pm, John Gordon wrote: > In <[email protected]> ksals > writes: > > > Please help a newbe. I have a string returned from an esygui > > multchoicebox that looks like > > this: ('ksals', '', 'alsdkfj', '3', '') I need to convert this to > > this: ['ksals', '', 'alsdkfj', '3', ''] > > That looks like a tuple which contains five strings. But you said it's > a string, so I'll believe you. > > >>> x = "('ksals', '', 'alsdkfj', '3', '')" > >>> print x > > ('ksals', '', 'alsdkfj', '3', '')>>> y = "[%s]" % x[1:-1] > >>> print y > > ['ksals', '', 'alsdkfj', '3', ''] > > -- > John Gordon A is for Amy, who fell down the stairs > [email protected] B is for Basil, assaulted by bears > -- Edward Gorey, "The Gashlycrumb Tinies" > > The original choice looks like this when I print it: print(choice) ('ksals', '', 'alsdkfj', '3', '') I need to submit these as defaults to a multenterbox. Each entry above ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box. I tried your suggestion so you must be right it is a tuple of 5 strings. But I need them to work in an instruction like fieldValues = eg.multenterbox(msg1,title, fieldNames, choice) fieldNames has 5 fields. -- http://mail.python.org/mailman/listinfo/python-list
Re: Converting a string to list for submission to easygui multenterbox
On May 1, 5:29 pm, John Gordon wrote:
> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com> ksals
> writes:
>
> > The original choice looks like this when I print it:
> > print(choice)
> > ('ksals', '', 'alsdkfj', '3', '')
> > I need to submit these as defaults to a multenterbox. Each entry above
> > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box.
> > I tried your suggestion so you must be right it is a tuple of 5
> > strings. But I need them to work in an instruction like
> > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice)
> > fieldNames has 5 fields.
>
> If you just need to convert a tuple to a list, that's easy. Call the
> built-in function list() and pass the tuple as an intializer:
>
> >>> choice = ('ksals', '', 'alsdkfj', '3', '')
> >>> print choice
>
> ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice)
> >>> print choice_list
>
> ['ksals', '', 'alsdkfj', '3', '']
>
> --
> John Gordon A is for Amy, who fell down the stairs
> [email protected] B is for Basil, assaulted by bears
> -- Edward Gorey, "The Gashlycrumb Tinies"
>
>
This is a small excert to show you what I get
for choice in easygui.multchoicebox(msg1, title,qstack):
if choice[0] == None:
print ("No entries made")
break
print("CHOICE IS: ",choice). CHOICE IS:
('', 'ksals', '', '', '')
c=list(choice)
print("C IS: ",c) . C IS: ['(',
"'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'",
"'", ',', ' ', "'", "'", ',', ' ', "'", "'",
')']
--
http://mail.python.org/mailman/listinfo/python-list
Re: Converting a string to list for submission to easygui multenterbox
On May 2, 1:57 pm, Laurent Pointal wrote:
> ksals wrote:
> > On May 1, 5:29 pm, John Gordon wrote:
> >> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com>
> >> ksals writes:
>
> >> > The original choice looks like this when I print it:
> >> > print(choice)
> >> > ('ksals', '', 'alsdkfj', '3', '')
> >> > I need to submit these as defaults to a multenterbox. Each entry above
> >> > ksals, "", "alsdkfj', 3 , '' need to fill the five fields in the box.
> >> > I tried your suggestion so you must be right it is a tuple of 5
> >> > strings. But I need them to work in an instruction like
> >> > fieldValues =3D eg.multenterbox(msg1,title, fieldNames, choice)
> >> > fieldNames has 5 fields.
>
> >> If you just need to convert a tuple to a list, that's easy. Call the
> >> built-in function list() and pass the tuple as an intializer:
>
> >> >>> choice = ('ksals', '', 'alsdkfj', '3', '')
> >> >>> print choice
>
> >> ('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice)
> >> >>> print choice_list
>
> >> ['ksals', '', 'alsdkfj', '3', '']
>
> >> --
> >> John Gordon A is for Amy, who fell down the stairs
> >> [email protected] B is for Basil, assaulted by bears
> >> -- Edward Gorey, "The Gashlycrumb Tinies"
>
> > This is a small excert to show you what I get
>
> > for choice in easygui.multchoicebox(msg1, title,qstack):
> > if choice[0] == None:
> > print ("No entries made")
> > break
>
> > print("CHOICE IS: ",choice) . CHOICE IS:
> > ('', 'ksals', '', '', '')
> > c=list(choice)
> > print("C IS: ",c) . C IS: ['(',
> > "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'",
> > "'", ',', ' ', "'", "'", ',', ' ', "'", "'",
> > ')']
>
> Looks like you have your tuple expression
> ('ksals', '', 'alsdkfj', '3', '')
> not as a tuple, but as a string. Do you convert it somewhere ?
>
> If you have it as a string, you can use eval() (not safe!) on the string to
> retrieve the tuple, then list() on the tuple to get a list.
>
> --
> Laurent POINTAL - [email protected]
> 3 allée des Orangers - 91940 Les Ulis - France
> Tél. 01 69 29 06 59
>
>
Thank you and everyone that helped me. I did finally figure it out
this morning. I am now converting for my use. I just didn't understand
what I was looking at
--
http://mail.python.org/mailman/listinfo/python-list
