I have a class that I'm trying to call a datetime
object on - I need it in a function as it is being monkey patched elsewhere. For some reason I'm getting an error. This is the class.
import datetime
class Boo(BaseOperator):
@apply_defaults
def __init__(
self,
*args,
**kwargs,
):
super().__init__(*args, **kwargs)
@staticmethod
def get_datetime() -> datetime.datetime:
return datetime.datetime.today()
def do(self):
name = f"hello/{self.get_datetime().strftime('%Y-%m-%d')}"
and the error i get when running it is:
def do(self):
> name = f"hello/{self.get_datetime().strftime('%Y-%m-%d')}"
E TypeError: 'datetime.datetime' object is not callable
can someone help? I don't understand what's wrong...
I think I found my error. It was in the monkey patching. I didn't actually think that would be causing issues.
I was monkey patching to return datetime.datetime(2021, 11, 11)
When I should have monkey patched to return lambda *args: datetime.datetime(2021, 11, 11)
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.