| 148 | |
| 149 | |
| 150 | class _TempFile(object): |
| 151 | def __enter__(self): |
| 152 | with NamedTemporaryFile(prefix="lightgbm_tmp_", delete=True) as f: |
| 153 | self.name = f.name |
| 154 | return self |
| 155 | |
| 156 | def __exit__(self, exc_type, exc_val, exc_tb): |
| 157 | if os.path.isfile(self.name): |
| 158 | os.remove(self.name) |
| 159 | |
| 160 | def readlines(self): |
| 161 | with open(self.name, "r+") as f: |
| 162 | ret = f.readlines() |
| 163 | return ret |
| 164 | |
| 165 | def writelines(self, lines): |
| 166 | with open(self.name, "w+") as f: |
| 167 | f.writelines(lines) |
| 168 | |
| 169 | |
| 170 | class LightGBMError(Exception): |