def __new__(cls, path=None, content=None, **kwargs): handle = open(path, 'w') if path else tempfile.NamedTemporaryFile(delete=False, **kwargs) if content: handle.write(content) handle.close() return FilePath.__new__(cls, handle.name)