copying a tuple to a list..

S

sergio

i have a result tuple from a MySQLdb call that would like to change in
place..

i would like to copy it to a list, so i can modify it in place, but i
cannot figure out how to do it.

the result typle is

dataResults

and i thought i could do something like

dataList = []

dataList = dataResults

but that doesn't work very well..

anyway.. thanks for the help..
 
S

Sybren Stuvel

(e-mail address removed) enlightened us with:
i have a result tuple from a MySQLdb call that would like to change in
place..

i would like to copy it to a list, so i can modify it in place, but i
cannot figure out how to do it.

dataResults = (1, 2, 12)
dataList = list(dataResults)

Sybren
 
D

Dennis Lee Bieber

and i thought i could do something like
dataList = dataResults
The name "dataList" is now attached to the same tuple as the name
"dataResults".

You want to convert the tuple (and since tuples are immutable, this
means copying the elements):

dataList = list(dataResults)

should do it. Of course, you now have both a list and a tuple occupying
memory. Maybe:

dataResults = list(dataResults)

which attaches the name "dataResults" to the newly created list object,
and (unless something else is holding on to it) leaves the tuple with no
name -- it can now be garbage-collected.
--
 
S

Scott David Daniels

i have a result tuple from a MySQLdb call that would like to change in
place..

What you probably want:
source = (1, 2, 'three')
wanted = list(source)

--Scott David Daniels
(e-mail address removed)
 

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

No members online now.

Forum statistics

Threads
474,432
Messages
2,571,682
Members
48,796
Latest member
Greg L.

Latest Threads

Top