我想在AMI图像的描述中找到日期

时间:2015-04-17 11:15:06

标签: python python-2.7 amazon-web-services boto

我正在尝试在图像描述中找到日期字符串。我已经这样做了:

enter image description here

我收到了这个输出。 enter image description here

当我试图取消注释该行时,它显示了这一点。 enter image description here

我想在AMI图像的描述中找到日期,以便找到在该日期注册的图像。

1 个答案:

答案 0 :(得分:1)

对您的代码进行以下更改: -

curdate = time.strftime("%d/%m/%Y")    #returns 17/04/2015.

你现在的回忆是“04/17/15”。但这不是你想要在给定字符串中找到的东西。

同样ami_image.description.find([curdate])也行不通。字符串的find方法需要str值。

但是根据您的要求,上述解决方案可能还不够,因为您可能并不总是知道要比较什么。因此,您可以使用re从说明中获取日期。

>>> import re
>>> patt = re.compile("([0-9]{2}/[0-9]{2}/[0-9]{4})")
>>> m = patt.search(ami_image.description)
>>> m.groups(0)
('17/04/2015',)