rajesh bojja
rajesh bojja

Reputation: 21

how to remove u' 's from output in python using scrapy?

when i run my command im getting output like shown below. how to remove u' getting every time?

[u'Massimo Eraldo Abate', u'Valentina Abate', u'Carlo Abbate', u'Francesca Abbate', u'Ines Abbate', u'Isabella Abbate', u'Maria Abbattista', u'Claudia Abbruzzese', u'Amina Abdeddaim', u'Jaber Sami Abdel', u'Lul Abdi Ali', u'Paola Abele', u'Massimo Abelli', u'Damiano Abeni', u'Gabriella Abolafio', u'Elisabetta Above', u'Jubin Abutalebi', u'Barbara Acaia', u'Domenico Acanfora', u'Massimo Accardo', u'Rosanna Accardo', u'Alice Acciaioli', u'Nicola Acciarri', u'Elisa Nicoletta Accornero', u'Davide Acerbi', u'Francesco Acerbi', u'Maria Teresa Achilarre', u'Gaetano Achille']

Upvotes: 0

Views: 275

Answers (3)

scriptso
scriptso

Reputation: 675

When you want to break down a nested list like that and just convert to string so you can output the list, you just need to strip and then join, which is a much more Pythonic way. But if that's not the case, when you yield as item, it won't show up.

But what I was mentioning:

foo = responce.etc('path to your data')
foo = [x.strip() for x in foo]
foo = ''.join(foo)

This will make your "strings/list" into an actual string of which you can then use to write... if that's the purpose?

Upvotes: 0

matsbauer
matsbauer

Reputation: 434

Your new full script for complete encoding process:

list_to_format = [u'Massimo Eraldo Abate', u'Valentina Abate', u'Carlo Abbate']

new_list = []

for value in list_to_format:
    new_list.append((value.encode('utf8').decode('utf-8')))

print(new_list)

Upvotes: 0

SunilThorat
SunilThorat

Reputation: 1748

You can use list comprehension to encode individual elements of list.

[u.encode("utf-8") for u in url_list]

Upvotes: 1

Related Questions