MCPcopy Create free account
hub / github.com/ipython/ipython / TemporaryWorkingDirectory

Class TemporaryWorkingDirectory

IPython/utils/tempdir.py:41–57  ·  view source on GitHub ↗

Creates a temporary directory and sets the cwd to that directory. Automatically reverts to previous cwd upon cleanup. Usage example: with TemporaryWorkingDirectory() as tmpdir: ...

Source from the content-addressed store, hash-verified

39
40
41class TemporaryWorkingDirectory(TemporaryDirectory):
42 """
43 Creates a temporary directory and sets the cwd to that directory.
44 Automatically reverts to previous cwd upon cleanup.
45 Usage example:
46
47 with TemporaryWorkingDirectory() as tmpdir:
48 ...
49 """
50 def __enter__(self):
51 self.old_wd = _os.getcwd()
52 _os.chdir(self.name)
53 return super(TemporaryWorkingDirectory, self).__enter__()
54
55 def __exit__(self, exc, value, tb):
56 _os.chdir(self.old_wd)
57 return super(TemporaryWorkingDirectory, self).__exit__(exc, value, tb)

Calls

no outgoing calls