user2492364
user2492364

Reputation: 6713

python:How to print the character from a variable with unicode string

I practice how to print unicode in python

My question is: how can I edit the code below to translate to unicode to print the result just 2014-07-16 ?

print 'day: %s  \n' %(releaseday)

My original output : day: [u'2014-07-16']
The result I want is: day:2014-07-16

I'd try print u'day: %s \n' %(unicode(releaseday)) And It didn't work

Please teach me Thank you

Upvotes: 2

Views: 283

Answers (2)

furas
furas

Reputation: 142814

If print gives [] in output then probably you have list in releaseday

You can:

1) get first element from that list

print 'day: %s  \n' % releaseday[0]

2) concatenate all elements from list

print 'day: %s  \n' % ''.join(releaseday)

3) iterate elements from list and print it separatly

for x in releaseday:
    print 'day: %s  \n' % x

But this is basic knowledge in "pure" python and have nothing to do with scrapy.

Upvotes: 1

alecxe
alecxe

Reputation: 474001

Since this is a Scrapy related question and I assume this is what the extract() returned - set TakeFirst() output processor on that specific field:

Returns the first non-null/non-empty value from the values received, so it’s typically used as an output processor to single-valued fields.

from scrapy.contrib.loader.processor import TakeFirst

class Product(scrapy.Item):
    day = scrapy.Field(output_processor=TakeFirst())

Here's what it does on the console:

>>> from scrapy.contrib.loader.processor import TakeFirst
>>> proc = TakeFirst()
>>> proc([u'2014-07-16'])
u'2014-07-16'

Upvotes: 0

Related Questions