0

A query to a database returns a tuple like this:

(u'Elia extends Feyenoord deal',)

Now I want to strip this down to the part which is in single quotes only, like a string. Something like:

'Elia extends Feyenoord deal'

How can I do this?

skrrgwasme
  • 9,358
  • 11
  • 54
  • 84
Code Bunny
  • 27
  • 6
  • 2
    Related and a Possible duplicate [How to convert single element tuple into string?](http://stackoverflow.com/q/28666811) – Bhargav Rao Jul 14 '16 at 20:01
  • 1
    [Python string prints as \[u'String'\]](http://stackoverflow.com/q/599625) – Bhargav Rao Jul 14 '16 at 20:06
  • @CodeBunny This is just the way Python displays the string as Bhargav Rao has explained. You are probably using Python2.x, right? – plamut Jul 14 '16 at 20:08
  • @plamut yes. Encoded to ascii and it is working fine – Code Bunny Jul 14 '16 at 20:10
  • Please don't edit your post to include the solution. You should [Accept](http://stackoverflow.com/help/accepted-answer) the answer that was most helpful to you, or post your own and accept that. The question box should only contain the question. I've edited your answer out of the question. It's up to you whether you want to accept plamut's answer or add your own instead. You should also leave off "thanks". I know it seems polite, but it's just considered noise here - it doesn't add any information to your question. – skrrgwasme Jul 14 '16 at 20:39

1 Answers1

5

Simple, just select the first element of the tuple (with index 0), which is the string you want:

>>> result = (u'Elia extends Feyenoord deal',)
>>> result[0]
'Elia extends Feyenoord deal'
>>> type(result[0])
<class 'str'>  # would be <type 'unicode'> in Python2.x
plamut
  • 3,085
  • 10
  • 29
  • 40