Skip to content

Instantly share code, notes, and snippets.

@internetimagery
Last active October 16, 2015 14:57
Show Gist options
  • Save internetimagery/3779b4fed6e52a4dfac4 to your computer and use it in GitHub Desktop.
Save internetimagery/3779b4fed6e52a4dfac4 to your computer and use it in GitHub Desktop.
temp file different approach
import os
import os.path
class Temp_Path(str):
def __del__(s):
if os.path.isfile(s): os.remove(s)
def __getattribute__(s, k):
if k[0] == "_": return str.__getattribute__(s, k)
raise AttributeError, "\"%s\" cannot be modified with \"%s\"" % (s.__class__.__name__, k)
# Example Usage
# import tempfile
# with tempfile.NamedTemporaryFile(delete=False) as f: path = Temp_Path(f.name)
# print path
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment