0

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!

2 Answers 2

3

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

Sign up to request clarification or add additional context in comments.

7 Comments

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 ?
' '.join([str(x) for x in r])
@silentghost : it doesnt show error right now for considering integer value ! but it neither show anything in output console!
@rahman: it's hard to know what the reason for this w/o seeing the actual code
@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?
|
0

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

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.