0

i've got a file that basically is a list, every entry is separated by carraige return. I'm trying to load this lines into a set() with this code:

with open('file','r') as f:
  entries = set()
  for row in f:
    entries.add(row)

The file looks like this:

entry1
entry2
entry3

In the end, the set looks like this if i print it:

set(['entry1\r\n', 'entry2\r\n'...])

I've got to do work with the set and i can't do searches and stuff with this EOL chars.

BlueStarry
  • 677
  • 1
  • 7
  • 13

1 Answers1

1

Use str.rstrip() to strip the carriage return

with open('file','r') as f:
  entries = set()
  for row in f:
    entries.add(row.rstrip())

Links

notorious.no
  • 4,919
  • 3
  • 20
  • 34