List question from newby

Joined
Apr 2, 2013
Messages
4
Reaction score
0
using 2.5 . i have the following data from a field in a database:
2,870,728,641
the code is:
for line in reader:
preds.append(line[-1])
# what i get is: ['2,870,728,641']
# when i use join
linklist=string.join(preds)
predlist.append(linklist)
# i get the same thing

what i need is:
[2,870,728,641] without the beginning & ending quote so i can i can iterate each as a separte value/word:
preds[0] renders 2, pres[1] renders 870 etc

or
['2','870','728','641'] to get separate words also

i can't seem to find the answer

thanks
GMAN
 
Last edited:
Joined
May 15, 2015
Messages
1
Reaction score
0
If 2.5 is anything like 2.6 then the quotes simply mean that the information is stored in a String and not a number.
Note the way python prints out stuff - with and without quotes.

Python 2.6.6 (r266:84292, Nov 21 2013, 10:50:32)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> my_strings=['1','2']
>>> my_numbers=[1,2]
>>> my_strings
['1', '2']
>>> my_numbers
[1, 2]
>>> '1' == 1
False
>>> int('1') == 1
True
>>> '1' == str(1)
True
>>> for stuff in my_numbers:
... print type(stuff)
... print stuff
...
<type 'int'>
1
<type 'int'>
2
>>> for stuff in my_strings:
... print type(stuff)
... print stuff
...
<type 'str'>
1
<type 'str'>
2
>>>
 

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,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top