title: Python Error: expected str, bytes or os.PathLike object when opening csv
body: <p>I'm running this python 3 code code:</p>
  <pre><code>import os
  import csv
  import glob
  import numpy as np
  import collections
  
  
  Prices = collections.namedtuple('Prices', field_names=['time', 'open', 'high', 'low', 'close', 'volume'])
  
  
  def read_csv(file_name, sep=',', filter_data=True, fix_open_price=False):
      print(&quot;Reading&quot;, file_name)                 
      with open(file_name, 'rt', encoding='utf-8') as fd:
          reader = csv.reader(fd, delimiter=sep)
          x = next(reader)                      
          if '&lt;OPEN&gt;' not in x and sep == ',':  
              return read_csv(file_name, ';') 
          indices = [x.index(s) for s in ('&lt;TIME&gt;', '&lt;OPEN&gt;', '&lt;HIGH&gt;', '&lt;LOW&gt;', '&lt;CLOSE&gt;', '&lt;VOL&gt;')]
          t, o, h, l, c, v = [], [], [], [], [], []
          count_out = 0
          count_filter = 0
          count_fixed = 0
          prev_vals = None
          for row in reader:
              vals = list(map(float, [row[idx] for idx in indices]))
              if filter_data and all(map(lambda v: abs(v-vals[0]) &lt; 1e-8, vals[:-1])):
                  count_filter += 1
                  continue
  
              to, po, ph, pl, pc, pv = vals
  
              # fix open price for current bar to match close price for the previous bar
              if fix_open_price and prev_vals is not None:
                  ppo, pph, ppl, ppc, ppv = prev_vals
                  if abs(po - ppc) &gt; 1e-8:
                      count_fixed += 1
                      po = ppc
                      pl = min(pl, po)
                      ph = max(ph, po)
              count_out += 1
              t.append(to)
              o.append(po)
              c.append(pc)
              h.append(ph)
              l.append(pl)
              v.append(pv)
              prev_vals = vals
      print(&quot;Read done, got %d rows, %d filtered, %d open prices adjusted&quot; % (count_filter + count_out, count_filter, count_fixed))
      return Prices(time=np.array(t, dtype=np.int),
                    open=np.array(o, dtype=np.float32),
                    high=np.array(h, dtype=np.float32),
                    low=np.array(l, dtype=np.float32),
                    close=np.array(c, dtype=np.float32),
                    volume=np.array(v, dtype=np.float32))
  
  def prices_to_relative(prices):
      &quot;&quot;&quot;   
      Convert prices to relative in respect to open price
      :param ochl: tuple with open, close, high, low     
      :return: tuple with open, rel_close, rel_high, rel_low
      &quot;&quot;&quot;   
      assert isinstance(prices, Prices)            
      rh = (prices.high - prices.open) / prices.open
      rl = (prices.low - prices.open) / prices.open
      rc = (prices.close - prices.open) / prices.open
      tm = prices.time
      return Prices(time=tm, open=prices.open, high=rh, low=rl, close=rc, volume=prices.volume)
  
  
  def load_relative(csv_file):
      return prices_to_relative(read_csv(csv_file))
  
  
  def price_files(dir_name):
      result = []
      for path in glob.glob(os.path.join(dir_name, &quot;*.csv&quot;)):
          result.append(path)
      return result
  
  
  def load_year_data(year, basedir='data'):
      y = str(year)[-2:] 
      result = {}        
      for path in glob.glob(os.path.join(basedir, &quot;*_%s*.csv&quot; % y)):
          result[path] = load_relative(path)
      return result      
  
  
  load_relative(read_csv('/home/darfeder/Downloads/9781838826994_Code/Chapter10/data/YNDX_150101_151231.csv'))
  </code></pre>
  <p>And I'm getting this error:</p>
  <blockquote>
  <p>TypeError: expected str, bytes or os.PathLike object, not Prices</p>
  </blockquote>
  <p>The csv file loaded is like this:</p>
  <div class="s-table-container">
  <table class="s-table">
  <thead>
  <tr>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  <th></th>
  </tr>
  </thead>
  <tbody>
  <tr>
  <td>20150105</td>
  <td>100100</td>
  <td>1064</td>
  <td>1064</td>
  <td>1064</td>
  <td>1064</td>
  <td>0</td>
  </tr>
  <tr>
  <td>20150105</td>
  <td>100200</td>
  <td>1064</td>
  <td>1064</td>
  <td>1064</td>
  <td>1064</td>
  <td>0</td>
  </tr>
  <tr>
  <td>20150105</td>
  <td>100300</td>
  <td>1064</td>
  <td>1064</td>
  <td>1064</td>
  <td>1064</td>
  <td>0</td>
  </tr>
  <tr>
  <td>20150105</td>
  <td>100400</td>
  <td>1064</td>
  <td>1064</td>
  <td>1064</td>
  <td>1064</td>
  <td>0</td>
  </tr>
  </tbody>
  </table>
  </div>
  <p>The error is in the &quot;prices_to_relative&quot; function</p>
  <p>Stack trace:</p>
  <blockquote>
  <p>--------------------------------------------------------------------------- TypeError                                 Traceback (most recent call
  last)  in 
  87
  88
  ---&gt; 89 load_relative(read_csv('/home/darfeder/Downloads/9781838826994_Code/Chapter10/data/YNDX_150101_151231.csv'))</p>
  <p> in load_relative(csv_file)
  69
  70 def load_relative(csv_file):
  ---&gt; 71     return prices_to_relative(read_csv(csv_file))
  72
  73</p>
  <p> in read_csv(file_name, sep,
  filter_data, fix_open_price)
  11 def read_csv(file_name, sep=',', filter_data=True, fix_open_price=False):
  12     print(&quot;Reading&quot;, file_name)
  ---&gt; 13     with open(file_name, 'rt', encoding='utf-8') as fd:
  14         reader = csv.reader(fd, delimiter=sep)
  15         x = next(reader)</p>
  <p>TypeError: expected str, bytes or os.PathLike object, not Prices</p>
  </blockquote>