Python Forum
help with strip function
Thread Rating:
  • 1 Vote(s) - 1 Average
  • 1
  • 2
  • 3
  • 4
  • 5
help with strip function
#1
I have a text file which is written like this

a

I have a text file which is written like this:
a \t b \t c \t d
d \t c \t d \t a
a \t b \t d \t a

I want to take this into a list so I wrote:
while(len(a_contents) > 0):
        list1.append(a_contents.strip())
        a_contents = a.read(size2read)
But the empty spaces become part of the list elements
How do i fix this?
Reply
#2
They appear to be tabs, not spaces
I welcome all feedback.
The only dumb question, is one that doesn't get asked.
My Github
How to post code using bbtags


Reply
#3
I change the strip parameter from blank to \t but it still include spaces in the list and also i want to remove the \n too
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Palindrome.strip pirts.emordnilaP RodNintendeaux 4 3,812 Oct-08-2017, 02:30 AM
Last Post: RodNintendeaux

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020