Using open() inside a subroutine

Grant Edwards grante at visi.com
Thu Feb 17 20:43:53 EST 2005


On 2005-02-18, imphasing <alex at fortworks.com> wrote:
> 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().

-- 
Grant Edwards                   grante             Yow!  Th' MIND is the Pizza
                                  at               Palace of th' SOUL
                               visi.com            



More information about the Python-list mailing list