0 votes
1 view
in Python by (41.8k 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 (95.7k 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.

Related questions

0 votes
1 answer
asked Sep 20 in Python by Sammy (41.8k points)
0 votes
1 answer
0 votes
1 answer
Welcome to Intellipaat Community. Get your technical queries answered by top developers !


Categories

...