0

I'm wondering why I get an error while trying to open a file in a tkinter button function.

def manage():
    output_file = os.open("Prices.txt", "w")
    output_file.write(",".join(HEADERS)+"\n")
    output_file.close()

Here is the simplified function, I get an error on the second line. The thing is it works just fine when I run it as is. However I had to convert it in a .exe to be able to run on computers without python, I've done it with pyinstaller and that maybe is the cause of the problem (not 100% sure tho).

martineau
  • 119,623
  • 25
  • 170
  • 301
Sujiwo
  • 1
  • 5
    [`os.open`](https://docs.python.org/3/library/os.html#os.open) is not the same as the builtin [`open`](https://docs.python.org/3/library/functions.html#open). It looks like you mean to be using the latter. You probably also want to use a [context manager](https://stackoverflow.com/q/1369526/11082165) instead of calling `close` manually: `with open("Prices.txt", "w") as output_file:` – Brian61354270 Jul 04 '22 at 15:27
  • @Flimm `os.open` expects a path as its first argument. You might be thinking of `os.fdopen`. The error is because the second argument (the flags) needs to be an integer. – Brian61354270 Jul 04 '22 at 15:31
  • 1
    I'd also suggest the study of the `pathlib` module, which also offers ways to open files. – Ulrich Eckhardt Jul 04 '22 at 15:56
  • The problem is almost certainly with how you created the `exe` file; update your question with the relevant details. – chepner Jul 04 '22 at 16:55
  • You really need a [mcve]; all you've shown is a function definition with no call, which won't produce any errors. – chepner Jul 04 '22 at 16:56

0 Answers0