简体   繁体   English

method_descriptor object 没有属性“现在” - 在 function 返回时

[英]method_descriptor object has no attribute 'now' - while returning in function

while running the below snippet the error is thrown on datetime.time.now() Error msg: method_descriptor object has no attribute 'now'在运行以下代码段时,在 datetime.time.now() 上抛出错误错误消息:method_descriptor object has no attribute 'now'

 from datetime import datetime
     def samplefun(file_path, max_width=0, width=0, height=0):
     file_dir = _get_file_dir(file_path)
     file_name = _get_file_name(file_path)
       
     return f"{file_dir}/thumbnails/{max_width}/pro_pic{datetime.time.now()}.jpg"

Remove the time namespace:移除time命名空间:

datetime.now()

EDIT:编辑:

If you need to remove certain parts of the timestamp, use replace :如果您需要删除时间戳的某些部分,请使用replace

datetime.now().replace(microsecond=0)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python - django:为什么我收到此错误:AttributeError:'method_descriptor'对象没有属性'今天'? - python - django: why am I getting this error: AttributeError: 'method_descriptor' object has no attribute 'today'? AttributeError: 'method_descriptor' object 在替换字符串时在 python 中没有属性 'df_new' - AttributeError: 'method_descriptor' object has no attribute 'df_new' in python when replacing string 在Python中,method_descriptor是什么? - In Python, what is a method_descriptor? kivy-TypeError:描述符“属性”需要一个“ kivy._event.EventDispatcher”对象,但收到一个“ method_descriptor” - kivy - TypeError: descriptor 'property' requires a 'kivy._event.EventDispatcher' object but received a 'method_descriptor' Spark无法pickle method_descriptor - Spark can't pickle method_descriptor Python内省:获取method_descriptor的参数列表? - Python introspection: get the argument list of a method_descriptor? 'DataFrame' object 在从 function 返回值时没有属性“数据不可用” - 'DataFrame' object has no attribute 'data not available' while returning the value from function rand.randrange 返回 'builtin_function_or_method' object 没有属性 'randrange' - rand.randrange returning 'builtin_function_or_method' object has no attribute 'randrange' AttributeError: 'function' 对象没有属性 'method' - AttributeError: 'function' object has no attribute 'method' "'builtin_function_or_method' object 没有属性 ' ' - "'builtin_function_or_method' object has no attribute ' '
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM