Last active
October 16, 2015 14:57
-
-
Save internetimagery/3779b4fed6e52a4dfac4 to your computer and use it in GitHub Desktop.
temp file different approach
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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