Take the 2-minute tour ×

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

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

and I want this r value printed as normal string!

share|improve this question
add comment

2 Answers

up vote 3 down vote accepted

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:]).

share|improve this answer
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 found Here int is found in the database content!...so ? –  rahman.bd Feb 22 '10 at 13:17
' '.join([str(x) for x in r]) –  Johannes Charra Feb 22 '10 at 13:26
@silentghost : it doesnt show error right now for considering integer value ! but it neither show anything in output console! –  rahman.bd Feb 22 '10 at 13:36
@rahman: it's hard to know what the reason for this w/o seeing the actual code –  SilentGhost Feb 22 '10 at 14:09
@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 Feb 22 '10 at 14:13
show 2 more comments

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

' '.join( map( str, x ) )
share|improve this answer
add comment

Your Answer


