tags:

views:

87

answers:

2

I have variable r=(u'East london,London,England', u'Mr.Baker in East london (at 2010-02-21 15:25:27.0)') in this format from webservice as a output from small program. How can I print these tuple data as normal string like:

East london,London,England   Mr.Baker in East london (at 2010-02-21 15:25:27.0) 

can anybody help me out of this please?Thanks in advance!

my code is giving now!

from sqlite3 import *

import feedparser
import codecs# newly added


data = feedparser.parse("some url")


conn = connect('location2.db')
curs = conn.cursor()

curs.execute('''create table location_top6
  ( id integer primary key,title text ,
        updated text)''')


for i in range(len(data['entries'])):
    curs.execute("insert into location_top6 values\
        (NULL, '%s', '%s')" % (data.entries[i].title,data.entries[i].summary))

conn.commit()
curs.execute("select * from location_top6")
for r in curs:
    print r

and I want this r value printed as normal string!

+3  A: 

just join on the separator, if it's space it would be:

' '.join(r)

edit: re your update code. Your table contains primary key, as can be seen from the table definition, that primary key is an integer. That's why you're getting that TypeError. The question is whether you want to print that primary key or not. If the answer is yes you could do the following:

' '.join(str(i) for i in r)

if no is the answer: you just need to ' '.join(r[1:]).

SilentGhost
well I tried it but showing error that : Traceback (most recent call last): File "F:\JavaWorkspace\Test\src\sqlite_example.py", line 28, in <module> print ''.join(row)TypeError: sequence item 0: expected string, int foundHere int is found in the database content!...so ?
rahman.bd
' '.join([str(x) for x in r])
jellybean
@silentghost : it doesnt show error right now for considering integer value ! but it neither show anything in output console!
rahman.bd
@rahman: it's hard to know what the reason for this w/o seeing the actual code
SilentGhost
@Silentghost: I have attached my actual code for your concerned in the above!could you please have a look of it?and another issue is that: I have some finnish language alphabet in that r variable representing location ,which need to handle with UTF-8, I guess so! But stuck with that problem too!.Can you please have a look it as well?
rahman.bd
@rahman: if the only thing that was changed in the above code is the printing of the tuple and it doesn't work, then it has nothing to do with printing. It means that your loop is not being executed, seeing as it has been executed before would led me to believe that something else was in fact changed. The localization issue would be a completely different question though, it will need to be asked separately.
SilentGhost
@Silentghost: it is now working ! surprisingly without any modification of codes! Thanks anyway!.But I guess as the feed contents are pretty much so that it need time to show the results! And for the localization issue..it also works without changing anything!...But is Sqlite default support UTF-8? I am surprised!
rahman.bd
A: 

If the sequence x contains other types than string, convert those first:

' '.join( map( str, x ) )
poke