Get full path to file `suffix` in temporary folder. This function doesn't creates file (only generate unique name). Also, it may return different paths in consecutive calling. Parameters ---------- suffix : str Suffix of file. Returns ------- str Pat
(suffix)
| 111 | |
| 112 | |
| 113 | def get_tmpfile(suffix): |
| 114 | """Get full path to file `suffix` in temporary folder. |
| 115 | This function doesn't creates file (only generate unique name). |
| 116 | Also, it may return different paths in consecutive calling. |
| 117 | |
| 118 | Parameters |
| 119 | ---------- |
| 120 | suffix : str |
| 121 | Suffix of file. |
| 122 | |
| 123 | Returns |
| 124 | ------- |
| 125 | str |
| 126 | Path to `suffix` file in temporary folder. |
| 127 | |
| 128 | Examples |
| 129 | -------- |
| 130 | Using this function we may get path to temporary file and use it, for example, to store temporary model. |
| 131 | |
| 132 | .. sourcecode:: pycon |
| 133 | |
| 134 | >>> from gensim.models import LsiModel |
| 135 | >>> from gensim.test.utils import get_tmpfile, common_dictionary, common_corpus |
| 136 | >>> |
| 137 | >>> tmp_f = get_tmpfile("toy_lsi_model") |
| 138 | >>> |
| 139 | >>> model = LsiModel(common_corpus, id2word=common_dictionary) |
| 140 | >>> model.save(tmp_f) |
| 141 | >>> |
| 142 | >>> loaded_model = LsiModel.load(tmp_f) |
| 143 | |
| 144 | """ |
| 145 | return os.path.join(tempfile.mkdtemp(), suffix) |
| 146 | |
| 147 | |
| 148 | @contextlib.contextmanager |
no outgoing calls
searching dependent graphs…