Using open() inside a subroutine

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • imphasing

    Using open() inside a subroutine

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

    def open():
    filePath=askope nfilename()

    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

  • Grant Edwards

    #2
    Re: Using open() inside a subroutine

    On 2005-02-18, imphasing <alex@fortworks .com> wrote:[color=blue]
    > Whenever I try to open a file inside a subroutine, like so:
    >
    > def open():
    > filePath=askope nfilename()
    >
    > fileOpen = open(filePath, "r")
    > fileContent = fileOpen.read()
    > fileOpen.close( )
    >
    > it tells me that "open() takes no arguments (2 given)"
    > Why is that?[/color]

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

    Don't call your function open().

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

    Comment

    • imphasing

      #3
      Re: Using open() inside a subroutine

      DUH. Thanks.
      can't beleive I missed that one...

      Alex

      Comment

      Working...