Login | Register For Free | Help
Search for: (Advanced)

Mailing List Archive: Python: Python

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

 

 

Python python RSS feed   Index | Next | Previous | View Threaded


kbsals5179 at gmail

May 1, 2012, 1:18 PM

Post #1 of 12 (699 views)
Permalink
Converting a string to list for submission to easygui multenterb​ox

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


gordon at panix

May 1, 2012, 1:26 PM

Post #2 of 12 (664 views)
Permalink
Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

In <316efebe-7f54-4054-96b1-51c7bb7b7b25 [at] f5g2000vbt> ksals <kbsals5179 [at] gmail> 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
gordon [at] panix B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

--
http://mail.python.org/mailman/listinfo/python-list


kroger at pedrokroger

May 1, 2012, 1:32 PM

Post #3 of 12 (667 views)
Permalink
Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

Have you tried to use the function list?:

foo = (1,2,3)
list(foo)

Cheers,

Pedro

--
http://pedrokroger.net



On May 1, 2012, at 5:18 PM, ksals wrote:

> 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

--
http://mail.python.org/mailman/listinfo/python-list


kbsals5179 at gmail

May 1, 2012, 2:09 PM

Post #4 of 12 (665 views)
Permalink
Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

On May 1, 4:26 pm, John Gordon <gor...@panix.com> wrote:
> In <316efebe-7f54-4054-96b1-51c7bb7b7...@f5g2000vbt.googlegroups.com> ksals <kbsals5...@gmail.com> 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
> gor...@panix.com              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


gordon at panix

May 1, 2012, 2:29 PM

Post #5 of 12 (661 views)
Permalink
Re: Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80 [at] d20g2000vbh> ksals <kbsals5179 [at] gmail> 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
gordon [at] panix B is for Basil, assaulted by bears
-- Edward Gorey, "The Gashlycrumb Tinies"

--
http://mail.python.org/mailman/listinfo/python-list


ramit.prasad at jpmorgan

May 1, 2012, 2:35 PM

Post #6 of 12 (662 views)
Permalink
RE: Converting a string to list for submission to easygui multenterb​ox [In reply to]

> > That looks like a tuple which contains five strings.

> The original choice looks like this when I print it:
>
> print(choice)
> ('ksals', '', 'alsdkfj', '3', '')

Based on the print statement, choice is a tuple or a string.
try doing `print(type(choice))`. On the assumption it is a
tuple and not a string you can convert it by doing:

choice = list(choice)

If it actually is a string I would do:
choice = list( ast.literal_eval( choice ) )


Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--


This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.
--
http://mail.python.org/mailman/listinfo/python-list


kbsals5179 at gmail

May 1, 2012, 2:50 PM

Post #7 of 12 (660 views)
Permalink
Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

On May 1, 5:29 pm, John Gordon <gor...@panix.com> wrote:
> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com> ksals <kbsals5...@gmail.com> 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
> gor...@panix.com              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


cs at zip

May 1, 2012, 4:29 PM

Post #8 of 12 (655 views)
Permalink
Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

Disclaimer: I have never used esygui.

On 01May2012 21:29, John Gordon <gordon [at] panix> wrote:
| In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1a80 [at] d20g2000vbh> ksals <kbsals5179 [at] gmail> writes:
| > The original choice looks like this when I print it:
|
| > print(choice)
| > ('ksals', '', 'alsdkfj', '3', '')

That's just print() printing a tuple.

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

Supposedly he should not need to. From:

http://www.ferg.org/easygui/tutorial.html#contents_item_10.2

the sentence: "The choices are specified in a sequence (a tuple or a
list)."

I do not believe that ksals needs to change anything.

Cheers,
--
Cameron Simpson <cs [at] zip> DoD#743
http://www.cskk.ezoshosting.com/cs/

Uh, this is only temporary...unless it works. - Red Green
--
http://mail.python.org/mailman/listinfo/python-list


cs at zip

May 1, 2012, 4:36 PM

Post #9 of 12 (657 views)
Permalink
Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

The tutorial suggests multchoicebox returns an interable of chosen
items, in fact probably a seqeunce. So...

On 01May2012 14:50, ksals <kbsals5179 [at] gmail> wrote:
| 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

This is the wrong test. "choice" is

| print("CHOICE IS: ",choice) ..... CHOICE IS:
| ('', 'ksals', '', '', '')

Does this really happen? This code associated with the for loop?

I'd expect easygui.multchoicebox to return a list (or tuple) and
"choice" to be a single string from the list. Did your print() call
happen after the quoted "for" loop or after a statement like this?

choice = easygui.multchoicebox(msg1, title, qstack)

| c=list(choice)
| print("C IS: ",c) ..... C IS: [.'(',
| "'", "'", ',', ' ', "'", 'k', 's', 'a', 'l', 's', "'", ',', ' ', "'",
| "'", ',', ' ', "'", "'", ',', ' ', "'", "'",
| ')']

Ok, that really does look like "choice" is a string. I'm really very
surprised.

What does this do?

choices = easygui.multchoicebox(msg1, title, qstack)
print("type(choices) =", type(choices))
print("choices =", repr(choices))

Cheers,
--
Cameron Simpson <cs [at] zip> DoD#743
http://www.cskk.ezoshosting.com/cs/

If you lie to the compiler, it will get its revenge. - Henry Spencer
--
http://mail.python.org/mailman/listinfo/python-list


laurent.pointal at free

May 2, 2012, 10:57 AM

Post #10 of 12 (651 views)
Permalink
Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

ksals wrote:

> On May 1, 5:29 pm, John Gordon <gor...@panix.com> wrote:
>> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com>
>> ksals <kbsals5...@gmail.com> 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
>> gor...@panix.com 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 - laurent.pointal [at] laposte
3 allée des Orangers - 91940 Les Ulis - France
Tél. 01 69 29 06 59

--
http://mail.python.org/mailman/listinfo/python-list


kbsals5179 at gmail

May 2, 2012, 1:55 PM

Post #11 of 12 (651 views)
Permalink
Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

On May 2, 1:57 pm, Laurent Pointal <laurent.poin...@free.fr> wrote:
> ksals wrote:
> > On May 1, 5:29 pm, John Gordon <gor...@panix.com> wrote:
> >> In <3b5f65c4-cd95-4bb4-94f2-0c69cf2b1...@d20g2000vbh.googlegroups.com>
> >> ksals <kbsals5...@gmail.com> 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
> >> gor...@panix.com              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 - laurent.poin...@laposte.net
> 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


rosuav at gmail

May 2, 2012, 9:29 PM

Post #12 of 12 (651 views)
Permalink
Re: Converting a string to list for submission to easygui multenterb​ox [In reply to]

On Thu, May 3, 2012 at 3:57 AM, Laurent Pointal <laurent.pointal [at] free> wrote:
> 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.

Are you saying that eval is not safe (which it isn't), or that it has
to be eval() and not safe_eval() to do this job? There's also
ast.literal_eval which ought to be safe for this situation (I think).

ChrisA
--
http://mail.python.org/mailman/listinfo/python-list

Python python RSS feed   Index | Next | Previous | View Threaded
 
 


Interested in having your list archived? Contact Gossamer Threads
 
  Web Applications & Managed Hosting Powered by Gossamer Threads Inc.