Stetson RDT
Stetson RDT

Reputation: 13

Python: internally defined open() causes "Type Error", "argument requires no arguments, 1 given"

This is quite likely something simple that I have an issue with, but I do not have another machine to figure out if it's my laptop's python version right now.

When I run my program, I recieve the following error: "Type Error: function open() requires no arguments (2 given)"

The code snippet in question:

    import tkinter as tk
    from tkinter import filedialog as fdg

    def update_queue():
            conf_file = open("config.txt", "a")
            fd = fdg.LoadFileDialog(master)
            file = fd.go(pattern="*.jpg")
            conf_file.write(file)
            conf_file.close()

I'm not yet too good with Python, and would appreciate any pointers ("Your code looks twistier than last night's burnt spaghetti" counts as well) as to why the open() function fails.

Also of note, if I call open outside of a defined function, it opens the file, and can complete all actions done on it, but if I close the file, I cannot re open the file from within a function. I attempted to use the os file functions, but recieved the error "LoadFileDialog does not work with buffer-defined file functions." Understandable.

If I use conf_file.flush(), assuming I opened it outside of a function, will it flush whatever I write/append, so that I can read from the file again later?

EDIT: What I mean, is, will this work all the time, or would this be considered a hack?

Upvotes: 1

Views: 884

Answers (2)

ThisFrickinSite
ThisFrickinSite

Reputation: 19

Assuming that open() was declared later on and you just didn't include it in the code, you probably declared it as

def open():
    #code here

If this is the case, you just didn't add in the arguments when declaring the function and it should be:

def open(x, y):
    #code here

where x and y could be anything you like.

Please come back and post the rest of your code (i highly doubt this is all of it) to get better answers. What is truly going on is at most a speculation on out part.

Upvotes: 0

swang
swang

Reputation: 219

is that the whole code? make sure you did not import another open function somewhere. or redefined it.

Upvotes: 1

Related Questions