title: Python - Getting TypeError with _io.BufferedReader
body: <p>I'm trying to implement the Prim Algorithm, but keep getting this error and I don't know what to do. Both the files are .txt files, the first one (the one assigned to matrizA) contains an adjacency matrix, while the second one is a list of the vertices names, one in each line.</p>
  <pre><code>import networkx as nx
  
  def peso(matrizA, u,v):
      return matrizA[u][v]
  
  def adjac(matrizA, u):
      L = []
      for x in range(len(matrizA)):
          L.insert(0,x)
      return L
  
  def extraiMin(Q):
      q = Q[0]
      Q.remove(Q[0])
      return q
  
  def decKey(Q, K):
      for i in range(len(Q)):
          for j in range(len(Q)):
              if K[Q[i]]&lt; K[Q[j]]:
                  s = Q[i]
                  Q[i] = Q[j]
                  Q[j] = s
  
  def prim(vList, matrizA, r):
      u = 0
      v = 0
      P = [None]*len(vList)
      K = [999999999]*len(vList)
  
      Q=[0]*len(V)
      for u in range(len(Q)):
          Q[u] = vList[u]
  
      K[r] = 0
      decKey(Q, K)
      while len(Q) &gt; 0:
          u = extraiMin(Q)   
          Adj = adjac(matrizA, u)
          for v in Adj:
              w = peso(matrizA, u)
  
              if Q.count(v) &gt; 0 and w &lt; K[v]:
                  P[v] = u
                  K[v] = w
                  decKey(Q, K)
      return P
  
  matrizA = open(&quot;C:\TrabalhoGrafos\Prim\MatrizAdjacencia_Pesos.txt&quot;, 'rb')
  V = open(&quot;C:\TrabalhoGrafos\Prim\AirportList_Vertices.txt&quot;, 'rb')
  
  P = prim(V, matrizA, 0)
  print (P)
  </code></pre>
  <p>The error PyCharm is showing me is this:</p>
  <blockquote>
  <p>Traceback (most recent call last):</p>
  <p>File &quot;C:/TrabalhoGrafos/Prim/Prim.py&quot;, line 74, in </p>
  <p>P = prim(V, matrizA, 0)</p>
  <p>File &quot;C:/TrabalhoGrafos/Prim/Prim.py&quot;, line 40, in prim</p>
  <p>P = [None]*len(vList)</p>
  <p>TypeError: object of type '_io.BufferedReader' has no len()</p>
  </blockquote>
  <p>I kept the other functions</p>