bsi*_*qui 1 python time datetime strptime
我正在尝试拆分日期时间...它适用于存储日期,但每当我尝试存储时间时我都会收到错误.
以下代码有效:
datetime = tweet.date.encode( 'ascii', 'ignore')
struct_date = time.strptime(datetime, "%a, %d %b %Y %H:%M:%S +0000")
date = time.strftime("%m/%d/%Y")
Run Code Online (Sandbox Code Playgroud)
但如果我添加以下行,我会收到一个错误:
time = time.strftime("%H:%M:%S")
Run Code Online (Sandbox Code Playgroud)
AttributeError:'str'对象没有属性'strptime'
您为名为的变量分配了一个字符串time
.使用不同的名称,它掩盖了您的time
模块导入.
tm = time.strptime(datetime, "%H:%M:%S")
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
18335 次 |
最近记录: |