Converting a string to list for submission to easygui multenterb​ox

K

ksals

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
 
J

John Gordon

In said:
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', '']
 
K

ksals

In said:
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.

('ksals', '', 'alsdkfj', '3', '')>>> y = "[%s]" % x[1:-1]
['ksals', '', 'alsdkfj', '3', '']

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.
 
J

John Gordon

In said:
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:
['ksals', '', 'alsdkfj', '3', '']
 
K

ksals

In said:
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:

('ksals', '', 'alsdkfj', '3', '')>>> choice_list = list(choice)
['ksals', '', 'alsdkfj', '3', '']
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', "'", ',', ' ', "'",
"'", ',', ' ', "'", "'", ',', ' ', "'", "'",
')']
 
L

Laurent Pointal

ksals said:
In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com>
ksals said:
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', '']
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.
 
K

ksals

ksals said:
In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com>
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', '']
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.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,020
Latest member
GenesisGai

Latest Threads

Top