Python "open" file got 'TypeError: function takes at least 2 arguments (1 given)'
Question: I've had a piece of code which basically read a txt file from directory.

    
    
    def img2vector(filename):
      returnVect=zeros((1,1024))
      fr=open(filename)
      for i in range(32):
        lineStr=fr.readline()
        for j in range(32):
          returnVect[0,32*i+j]=int(lineStr[j])
      return returnVect
    

When I run img2vector(PATHTOMYFILE) I've got the error message:

    
    
        fr=open(filename)
    TypeError: function takes at least 2 arguments (1 given)
    

But, when I try: ` fr=open(PATHTOMYFILE) ` it's correct without any problem.


Answer: The most likely cause is that you define (or import) a function called
`open()` that shadows the [built-
in](https://docs.python.org/2/library/functions.html#open).

