python - How can I get python3 file.close to release the file lock? -
Python3 file.close is not apparently giving the file, so it can not be used by Win7 commands.
To: Wise:
Import OS, time hfile = "condition .htm" hf = open (hfile, "w") hf.write (str (buf) )) Hf Close time.Sleep (2) # Close enough time to os.system (hfile) # Run the html file in the default browser
This is an error message from Win7 The result is saying, that the file can not be accessed because it is currently in use, however, it can be easily used after the dragon program is over.
Yes, I know that similar questions have been given here, but I did not see a common answer.
You can simply close ()
Forgot to call hf.close # incorrect hf.close () # correct
You can see that hm.close
just do not call it Gives you a bound method:
& gt; & Gt; & Gt; Hm.close & lt; Built-in method, close the _io.TextIOWrapper object at 0x7ffe8ec74b40 & gt; As Pedriak Chalami Hamm said, if you just use with syntax, then you do not have to do this: Hf: hf.write (str (Bf) open # (with hfile, 'w') # automatically shutdown
Comments
Post a Comment