2

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.

1
  • In what context did you try the open(PATHTOMYFILE) call? because that's not the same function.
    – Martijn Pieters
    Apr 19, 2014 at 11:36

2 Answers 2

3

The most likely cause is that you define (or import) a function called open() that shadows the built-in.

2
  • @sshashank124: It is hard to be sure, but I suspect that the OP tried that other command in a different context (i.e. he was calling the built-in open()).
    – NPE
    Apr 19, 2014 at 11:33
  • Possibly, It's hard to be sure since the question is so limited in providing all the relavant code. Apr 19, 2014 at 11:35
0

You must have imported both os and numpy

You can do

from numpy import *
import operator
import os

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.