2

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

1
  • Note that TakeFirst() is the recommended way to get a first value from an extracted list. If you are using extract() to get the list, you can just use extract_first() to get the first item or None nowadays. Commented Jan 31, 2016 at 14:58

2 Answers 2

1

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.

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

Comments

0

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'

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.