1

Real quick question, what is the difference between line.strip("\n") and line.rstrip(os.linesep)? Especially, when using them in the Fasta file and other bioinformatics fields.

1 Answers1

1

line.strip("\n") removes the new-line character for UNIX and UNIX-like OSs. On the other side, line.strip(os.linesep) would automatically change to the correct new-line character for your current operation system (Mac OS, Linux, Windows, etc)

Shinra tensei
  • 1,283
  • 9
  • 21
Zaid Al Shattle
  • 1,454
  • 1
  • 12
  • 21
  • But the newline sequence for Windows is `\r\n`, not `\n`. `\n` is the newline sequence for Unix and Unix-like systems, and `\r` is the newline sequence for the traditional MacOS (note the capitalization) but not the Unix-based macOS. – Jörg W Mittag Oct 04 '21 at 11:49
  • Apologies, I confused that part. I will correct that now. – Zaid Al Shattle Oct 04 '21 at 11:49
  • Dank! But why the python doc says never use the os.sepline in any cases? [https://docs.python.org/3/library/os.html#os.linesep] – Andrew Swainskeren Oct 04 '21 at 11:50
  • Check the question linked as duplicate (What is os.linesep for), as it will contain the answer to that question – Zaid Al Shattle Oct 04 '21 at 11:51
  • Because you don't know what system that file is going to be used in, so if you use the specific character for windows the file will not be correct when used on Linux, for example. – Shinra tensei Oct 04 '21 at 11:51
  • I think Andrew meant why the os.sepline should *not* be used. Which is a bit of a confusion about the "text mode". @Shinratensei – Zaid Al Shattle Oct 04 '21 at 11:52