[Solved] Attribute Error: ‘list’ object has no attribute ‘split’

Hello readers, Today In this article I am going to show you how to solve – Attribute Error: ‘list’ object has no attribute ‘split’ error in Python. So here I will explain all the possible solutions.

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

How to Attribute Error: ‘list’ object has no attribute ‘split’ Occurs?

This is a common error to use the split() method on a list you might face while running a Python application. It looks as like below:

"AttributeError: 'list' object has no attribute 'split'

How To Solve Attribute Error: ‘list’ object has no attribute ‘split’ Error?

  • How To Solve Attribute Error: ‘list’ object has no attribute ‘split’ Error?

To Solve Attribute Error: ‘list’ object has no attribute ‘split’ Error to call split a list of strings, only a string. not call split on the whole list of lines. So, you need to split each line, not the whole thing. Now, Your error must be solved.

  • Attribute Error: ‘list’ object has no attribute ‘split’ Error?

To Solve Attribute Error: ‘list’ object has no attribute ‘split’ Error to call split a list of strings, only a string. not call split on the whole list of lines. So, you need to split each line, not the whole thing. Now, Your error must be solved.

Solution 1: Use Splitting a List of Strings

def getQuakeData():
    filename = input("Please enter the quake file: ")
    readfile = open(filename, "r")
    readlines = readfile.readlines()
    Types = [line.split(",") for line in readlines]
    xs = [Type[1] for Type in Types]
    ys = [Type[2] for Type in Types]
    for x, y in zip(xs, ys):
        print(x,y)

getQuakeData()

Now, I hope your error must be solved.

Summary

It’s all About this error. Hope We solved Your error. Comment below Your thoughts and your queries. Also, Comment below which solution worked for you?

Related Articles

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Categories