Back

Explore Courses Blog Tutorials Interview Questions
0 votes
2 views
in Python by (47.6k points)

This is my problem.

I'm trying to read a text file and then convert the lines into floats. The text file has \n and \t in it though I don't know how to get rid of it.

I tried using line.strip() but it didn't take it off and I got an error when I wanted to convert the stuff to floats. I then tried line.strip("\n") but that didn't work either. My program works fine when I take out the \t and \n from the text file, but it's part of the assignment to get it to work with them.

I really don't know why this isn't working. Thanks for any help.

1 Answer

0 votes
by (106k points)

For striping in Python, you can use the below-mentioned code:-

mylist = [] 

for line in lines: 

mylist.append(line.strip().split('\t')

For getting a python list with only the field values for all the lines of data.

Browse Categories

...