This is used for formatting strings with values that need to be updated at that time, such as the current time or working directory.
| 3 | """ |
| 4 | |
| 5 | class LazyEvaluate(object): |
| 6 | """This is used for formatting strings with values that need to be updated |
| 7 | at that time, such as the current time or working directory.""" |
| 8 | def __init__(self, func, *args, **kwargs): |
| 9 | self.func = func |
| 10 | self.args = args |
| 11 | self.kwargs = kwargs |
| 12 | |
| 13 | def __call__(self, **kwargs): |
| 14 | self.kwargs.update(kwargs) |
| 15 | return self.func(*self.args, **self.kwargs) |
| 16 | |
| 17 | def __str__(self): |
| 18 | return str(self()) |
| 19 | |
| 20 | def __format__(self, format_spec): |
| 21 | return format(self(), format_spec) |
no outgoing calls