title: Decode ebcdic to ascii/readable text in python
body: <p>I have a IBM mainframe file encoded in 'cp500' (I was informed) which is to be decoded to ascii or readable text. The file is taken from unix server transferred to windows using IPSwitch tool.</p>
  
  <p>I already tried the below codes and couldn't achieve what I desire:</p>
  
  <pre><code>sample data = 'ðñðòðõÅäù@@@@@@@ððð :BÄÑðò÷øò@@@JaÈK' - in txt file
  
  import codecs
  
  with open(file, "rb") as ebcdic:
      ascii_txt = codecs.decode(ebcdic, "cp500")
      print(ascii_txt)
  </code></pre>
  
  <p>This is producing type error</p>
  
  <pre><code>"TypeError: decoding with 'cp500' codec failed (TypeError: a bytes-
  like object is required, not '_io.BufferedReader')"
  </code></pre>
  
  <p>Then I tried these two,</p>
  
  <pre><code>with open(file, 'r', encoding='cp500') as f:
      for line in f:
          print(line)
  
  with codecs.open(file, 'r', encoding='cp500')
      for line in f:
          print(line)
  </code></pre>
  
  <p>I also tried International encoding "cp1140" format as well - </p>
  
  <pre><code>with open(file, 'r', encoding="cp1140") as f:
      for line in f:
         print(line)
  </code></pre>
  
  <p>I expect a readable output - a copybook layout - something like this...</p>
  
  <pre><code>0001***********
  0002...........
  0003...........
  </code></pre>
  
  <p>But All the above three are printing output as :</p>
  
  <pre><code>C¢C£C¢C¥C¢C§CeCuC¾       C¢C¢C¢âCdCjC¢C¥C¼C½C¥   [/Ch.
  </code></pre>
  
  <p>And I also tried reading the file in "rb" mode:</p>
  
  <pre><code>with open(file, 'rb') as f:
      for line in f:
          print(line)
  </code></pre>
  
  <p>And this is producing below output -</p>
  
  <pre><code>b'\xc3\xb0\xc3\xb1\xc3\xb0\xc3\xb2\xc3\xb0\xc3\xb5\xc3\x85\xc3\xa4\xc3\xb9@@@@@@@\xc3\xb0\xc3\xb0\xc3\xb0 :B\xc3\x84\xc3\x91\xc3\xb0\xc3\xb2\xc3\xb7\xc3\xb8\xc3\xb2@@@Ja\xc3\x88K'
  </code></pre>
  
  <p>This is the first time I'm dealing with ebcdic/mainframe files - Any help in decoding this would be appreciated!</p>
  
  <p>Thanks in Advance :)</p>