title: How would I adapt the file() function in Python2 to a Python3 function?
body: <h2>Primary Issue</h2>
  
  <p>I am currently trying to run <a href="https://github.com/MTG/DeepConvSep" rel="nofollow noreferrer">this</a> particular Github Project on my Mac OS. It was most certainly coded for a system running Python 2. However, I am running Python3 and I need to make a few modifications to the program. Most of these modifications work seamlessly, except for the one below.</p>
  
  <p>When I run the program with this command...</p>
  
  <pre><code>python3 separate_dsd.py -i ./../../Ricotti\ \&amp;\ Alburquerque\ -\ Dont\ You\ Believe\ Me.mp3 -o ./ -m ./../../model1.pkl
  </code></pre>
  
  <p>...I get the error <code>NameError: name 'file' is not defined</code>. File has been replaced with <code>io.open</code> within Python3. However, simply replacing the function call with <code>io.open</code> is giving me an error. </p>
  
  <p>The specific line is, <code>f=file(filename,'rb')</code> of the code block: </p>
  
  <pre><code>def load_model(filename):
      f=file(filename,'rb')
      params=pickle.load(f)
      f.close()
      return params
  </code></pre>
  
  <p>This resides in the file <code>/DeepConvSep/examples/dsd100/separate_dsd.py</code>. Now how would I go about replacing the exact behaviour of <code>file(filename,'rb')</code> with a <code>io.open</code>? </p>
  
  <hr>
  
  <h2>Responses to Answers Below</h2>
  
  <p>Currently I tried to follow @abarnert's suggestions and changed my code to: </p>
  
  <pre><code>def load_model(filename):
      with open(filename, 'rb') as f:
          return pickle.load(f)
  </code></pre>
  
  <p>But I still get the error: </p>
  
  <pre><code>Traceback (most recent call last):
    File "separate_dsd.py", line 336, in &lt;module&gt;
      main(sys.argv[1:])
    File "separate_dsd.py", line 333, in main
      train_auto(inputfile,outdir,model,0.3,30,25,32,513)
    File "separate_dsd.py", line 250, in train_auto
      params=load_model(model)
    File "separate_dsd.py", line 19, in load_model
      params=pickle.load(f)
  UnicodeDecodeError: 'ascii' codec can't decode byte 0xbb in position 2: ordinal not in range(128)
  </code></pre>