Make a new tempfile and return its filename. This makes a call to tempfile.mkstemp (created in a tempfile.mkdtemp), but it registers the created filename internally so ipython cleans it up at exit time. Optional inputs: - data(None): if data is given, it
(self, data=None, prefix='ipython_edit_')
| 3935 | return cmd |
| 3936 | |
| 3937 | def mktempfile(self, data=None, prefix='ipython_edit_'): |
| 3938 | """Make a new tempfile and return its filename. |
| 3939 | |
| 3940 | This makes a call to tempfile.mkstemp (created in a tempfile.mkdtemp), |
| 3941 | but it registers the created filename internally so ipython cleans it up |
| 3942 | at exit time. |
| 3943 | |
| 3944 | Optional inputs: |
| 3945 | |
| 3946 | - data(None): if data is given, it gets written out to the temp file |
| 3947 | immediately, and the file is closed again.""" |
| 3948 | |
| 3949 | dir_path = Path(tempfile.mkdtemp(prefix=prefix)) |
| 3950 | self.tempdirs.append(dir_path) |
| 3951 | |
| 3952 | handle, filename = tempfile.mkstemp(".py", prefix, dir=str(dir_path)) |
| 3953 | os.close(handle) # On Windows, there can only be one open handle on a file |
| 3954 | |
| 3955 | file_path = Path(filename) |
| 3956 | self.tempfiles.append(file_path) |
| 3957 | |
| 3958 | if data: |
| 3959 | file_path.write_text(data, encoding="utf-8") |
| 3960 | return filename |
| 3961 | |
| 3962 | def ask_yes_no(self, prompt, default=None, interrupt=None): |
| 3963 | if self.quiet: |