0

Okay so I need to do a file test for a program by creating/opening(if the file exists) and append some text to it to confirm that it works. Before I started adding in modules in the test went perfectly fine but once I finished putting in the modules and started working with the GUI with the Tkinter module now I get an error that an integer is required. There is a post about it but in there the person just messed up something with readline() which is not the case for me. I think it has to do with the JSON module or the fact that I added in #!/usr/bin/env python after the file test but I don't know.

Here's my code

#!/usr/bin/env python

#shit to import
from json import *
from os import *
from sys import *
from numpy import *
from datetime import *
from tkinter import *

#testing
with open("test.txt","a") as file:
    file.read()
    file.write("The test has been completed \n")

#GUI
win = Tk()
win.mainloop()
Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
alan
  • 23
  • 2
  • 1
    It is not a good practice to use the `file` as variable name. Consider switching to a different variable name such as `inFile`. Regarding your error, it has to do with `from os import *` line as it is mentioned in a different question [here](https://stackoverflow.com/questions/1046656/an-integer-is-required-open). – Vasilis G. Aug 13 '18 at 11:24
  • 3
    `open` used to be nice. `os.open` is a different thing, that wants `flags` as the second argument (which have to be integer). `from os import *` replaced `open` with `os.open`. I highly suggest not doing `from stuff import *`, as you never know what could get overwritten. – Amadan Aug 13 '18 at 11:26
  • 2
    @VasilisG. why? `file` isn't a builtin in Python 3 (they're not shadowing anything); the `from blah import *` is more probabilistic and worse style – Chris_Rands Aug 13 '18 at 11:28
  • @Chris_Rands you're absolutely right. That was my mistake. – Vasilis G. Aug 13 '18 at 11:32

1 Answers1

3

This is because you are doing import * stuff and builtin open() function replaced by os.open().

It's a bad idea to use import * stuff. Just import what you really need and you'll be happy ;)

leotrubach
  • 1,509
  • 12
  • 15