开发者

Printing tuple data in normal text in Python

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 add开发者_StackOverflow中文版ed


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!


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


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜