title: How to skip new lines for comparison in python?
body: <p>I have a python code which compare 2 text file and show if they have differences. first of all i sort files then remove their spaces that are at the end of text after sort then do the comparison.</p>
  
  <pre><code>#!/usr/bin/env python
  
  import difflib
  from pathlib import Path
  
  path1=Path('/data1/Dir/thesaurus/file1')
  path2=Path('/data1/Dir/thesaurus/file2')
  
  text1 = open(str(path1)).readlines()
  text1.sort(key=lambda x: x.strip('#').rsplit('.', 1)[0])
  text2 = open(str(path2)).readlines()
  text2.sort(key=lambda x: x.strip('#').rsplit('.', 1)[0])
  
  for line in difflib.unified_diff(text1, text2, n=0):
  print line,
  </code></pre>
  
  <p>actually those files for comparison are the <code>/etc/passwd</code> of different servers. this code worked good but recently i found out that it is not returning the correct output for some servers because of <code>\n</code>. how i can eliminate these <code>\n</code> in my comparison?</p>
  
  <p>for example, the file1 and file2 have this content:</p>
  
  <pre><code>@=&gt; cat file1
  wise:x:wuser:/home/wise:/sbin/nologin
  nafs:x:user:/home/nafs:/sbin/nologin
  khor:x:khor:/home/khor:/bin/bash
  jari:x:user:/home/jari:/sbin/nologin
  test:x:Test:/home/test:/sbin/nologin
  zabbix:x:Zabbix Agent:/home/zabbix:/usr/sbin/nologin
  @=&gt; cat file2
  wise:x:wuser:/home/wise:/sbin/nologin
  nafs:x:user:/home/nafs:/sbin/nologin
  jari:x:user:/home/jari:/sbin/nologin
  zabbix:x:Zabbix Agent:/home/zabbix:/usr/sbin/nologin
  </code></pre>
  
  <p>what i expect:</p>
  
  <pre><code>---
  +++
  @@ -6 +5,0 @@
  -khor:x:khor:/home/khor:/bin/bash
  @@ -8 +7 @@
  -test:x:Test:/home/test:/sbin/nologin  
  </code></pre>
  
  <p>what i get:</p>
  
  <pre><code>---
  +++
  @@ -1 +1 @@
  -nafs:x:user:/home/nafs:/sbin/nologin
  +nafs:x:user:/home/nafs:/sbin/nologin
  @@ -6 +5,0 @@
  -khor:x:khor:/home/khor:/bin/bash
  @@ -8 +7 @@
  -jari:x:user:/home/jari:/sbin/nologin
  +jari:x:user:/home/jari:/sbin/nologin
  @@ -12 +10,0 @@
  -test:x:Test:/home/test:/sbin/nologin
  </code></pre>
  
  <p>i ran my code without the comparison part and printed the <code>text1</code> and <code>text2</code> to find the problem and i saw that there is an <code>\n</code> next to lines that they were returned incorrectly in one file and not in other file.</p>