我想在 AMI 图像的描述中找到日期
I want to find the date in the description of AMI image
我正在尝试在 image.I 的描述中查找日期字符串:
我得到了这个输出。
当我试图取消注释该行时,它显示了这一点。
我想在AMI镜像的描述中找到日期,这样我就可以找到在那个日期注册的镜像。
对您的代码进行以下更改:-
curdate = time.strftime("%d/%m/%Y") #returns 17/04/2015.
您当前的 curdate 正在返回“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',)
我正在尝试在 image.I 的描述中查找日期字符串:
我得到了这个输出。
当我试图取消注释该行时,它显示了这一点。
我想在AMI镜像的描述中找到日期,这样我就可以找到在那个日期注册的镜像。
对您的代码进行以下更改:-
curdate = time.strftime("%d/%m/%Y") #returns 17/04/2015.
您当前的 curdate 正在返回“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',)