close

[Solved] AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character

Hello Guys, How are you all? Hope You all Are Fine. Today I get the following error AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character in python. So Here I am Explain to you all the possible solutions here.

Without wasting your time, Let’s start This Article to Solve This Error.

How AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character Error Occurs?

Today I get the following error AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character in python.

How To Solve AttributeError: ‘list’ object has no attribute ‘replace’ when trying to remove character Error ?

  1. How To Solve AttributeError: 'list' object has no attribute 'replace' when trying to remove character Error ?

    To Solve AttributeError: 'list' object has no attribute 'replace' when trying to remove character Error xpath method returns a list, you need to iterate items.

  2. AttributeError: 'list' object has no attribute 'replace' when trying to remove character

    To Solve AttributeError: 'list' object has no attribute 'replace' when trying to remove character Error xpath method returns a list, you need to iterate items.

Solution 1

xpath method returns a list, you need to iterate items.

kickoff = [item.replace("'", "") for item in kickoff]

Solution 2

kickoff = tree.xpath('//*[@id="page"]/div[1]/div/main/div/article/div/div[1]/section[2]/p[1]/b[1]/text()')

This code is returning list not a string.Replace function will not work on list.

[i.replace("'", "") for i in kickoff ]

Summery

It’s all About this issue. Hope all solution helped you a lot. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you? Thank You.

Also, Read