'I am trying to do a split line by tab in an excel but it isn't working
I am trying to split line by tab with excel file to separate all the things in the cells. My code currently looks like this but something isn't right. I need to tell python to read my excel file and use split() to separate everything the cells. What am I doing wrong?
lines = f.readlines()
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
~\AppData\Local\Temp/ipykernel_15432/3489501303.py in <module>
----> 1 lines.split("\t")
AttributeError: 'list' object has no attribute 'split'
Solution 1:[1]
I have a list in my "text_text.txt" file. With following config I have received same error.
with open("text_text.txt") as f:
a = f.readlines()
a1 = a.split()
print(a1)
output:
AttributeError: 'list' object has no attribute 'split'
you can use "".join then try to split as following, so that your data should be splitted. you can not split list as there is no such attribute.
with open("text_text.txt") as f:
a = f.readlines()
a1 = "".join(a)
a2 = a1.split()
print(a2)
The output right now is as following without any error:
['[1,', '2,', '3,', "'hello',", "'world']"]
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Baris Ozensel |
