Make a name for a block of code, and cache the code. Parameters ---------- code : str The Python source code to cache. number : int A number which forms part of the code's name. Used for the execution counter. Returns --
(self, code, number=0)
| 113 | return self.flags |
| 114 | |
| 115 | def cache(self, code, number=0): |
| 116 | """Make a name for a block of code, and cache the code. |
| 117 | |
| 118 | Parameters |
| 119 | ---------- |
| 120 | code : str |
| 121 | The Python source code to cache. |
| 122 | number : int |
| 123 | A number which forms part of the code's name. Used for the execution |
| 124 | counter. |
| 125 | |
| 126 | Returns |
| 127 | ------- |
| 128 | The name of the cached code (as a string). Pass this as the filename |
| 129 | argument to compilation, so that tracebacks are correctly hooked up. |
| 130 | """ |
| 131 | name = code_name(code, number) |
| 132 | entry = (len(code), time.time(), |
| 133 | [line+'\n' for line in code.splitlines()], name) |
| 134 | linecache.cache[name] = entry |
| 135 | linecache._ipython_cache[name] = entry |
| 136 | return name |
| 137 | |
| 138 | @contextmanager |
| 139 | def extra_flags(self, flags): |