如何删除推特上的日期?

2024-05-23 20:56:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我需要一些关于这个的建议

Mon Apr 06 22:19:45 PDT @switchfoot http://twitpic.com/2y1zl - Awww, that's a bummer. :( You shoulda got David Carr of Third Day to do it. ;D
Mon Apr 06 22:19:49 PDT is upset that he can't update his Facebook by texting it... and might cry as a result :( School today also. Blah!
Mon Apr 06 22:19:53 PDT @Kenichan I dived many times for the ball. Managed to save 50% :( The rest go out of bounds
Mon Apr 06 22:19:57 PDT my whole body feels itchy and like its on fire :(

我怎样才能移除这个星期一4月6日22:19:57 PDT?使用正则表达式?在


Tags: andoftocomhttpthatit建议
3条回答

如果这是一个字符串,只需在第一个PDT上拆分行:

for line in tweets.splitlines():
    print line.split(' PDT ', 1)[1]

在第一次出现字符PDT(带空格)时将行拆分,并打印结果的后半部分。在

但是也许您可以首先阻止输出字符串的代码添加日期?在

for line in lines:
    print line[24:]

如果日期/时间格式始终相同,则可能很简单。在

如果它们都是以相同方式存储的字符串,则只需执行拆分:

tweet = "Mon Apr 06 22:19:57 PDT SomeGuy Im not white enough to be excited for a new version of Windows".

tweet= tweet.split(None, 5)[-1]

结果推特

"SomeGuy Im not white enough to be excited for a new version of Windows"

相关问题 更多 >