python - Why does tempfile seem to delete itself within a with statement? -


This program is a browser designed to circumvent the proxy settings as you can see when When the data is processed, it is inserted into a file and is opened in the default browser. However, when I open it in Chrome (I do not know it is important), it says:

This webpage is not found

A web page was found for the web address: file: /// C: /Users/Thornton/appdata/local/temp/tmpreb9zp.html

Code: ERR_FILE_NOT_FOUND

Here is the code:

  import urllib.request import webbrowser tkinter import * import tempfile from square browser: def __init __ (Self, Master): Global E1 self.proxy_handler = urllib.request.ProxyHandler (Proxy = None) self.opener = u Rllib.request.build_opener (self.proxy_handler) label (master, text = 'full path'). Grid (line = 0) e1 = entry (master) e1.grid (line = 0, column = 1) button (master, text = 'go', command = self.browse) .grid (line = 0, column = 2 ) Root.bind ('; self.browse) @staticmethod def Parsed (data): initial = str (data) [2: -1] line = initial.split (' \\ n ' ) Return lines DEF navigate (self, query): feedback = self.opener.open (query) html = self.parsed (response.read ()) Return HTML DEF Browse (self): raw_data = self.navigate (e1.get ()) Clean_data = self.parsed (raw_data) tempfile.NamedTemporaryFile (suffix = 'HTML.') With cache: (line_enata line.encode ('UTF-8') in cache.writelines webbrowser .open_new_tab (cache.name) root = t () root.wm_attributes ('- supreme', 1) application = Browser (root) root.mainloop ()  

Because tempfiles are, and Statement with statement does this, and does not wait for the WebBuser module to complete. From:

For non-UNIX platforms, or when a remote browser is available on Unix, the control process will not wait for the user to end up with the browser


Comments