Using open() inside a subroutine

I

imphasing

Whenever I try to open a file inside a subroutine, like so:

def open():
filePath=askopenfilename()

fileOpen = open(filePath, "r")
fileContent = fileOpen.read()
fileOpen.close()

it tells me that "open() takes no arguments (2 given)"
Why is that? and how can I get around that so I can open a file in a
subroutine?

Thanks,
Alex
 
G

Grant Edwards

Whenever I try to open a file inside a subroutine, like so:

def open():
filePath=askopenfilename()

fileOpen = open(filePath, "r")
fileContent = fileOpen.read()
fileOpen.close()

it tells me that "open() takes no arguments (2 given)"
Why is that?

Because you defined open() as taking no arguments. You're
calling your own open() function, not the builtin one.
and how can I get around that so I can open a file in a
subroutine?

Don't call your function open().
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,774
Messages
2,569,599
Members
45,165
Latest member
JavierBrak
Top