Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/320.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
博托+;Python+;AWS S3:如何获取特定文件的上次修改属性?_Python_Python 2.7_Amazon Web Services_Amazon S3_Boto3 - Fatal编程技术网

博托+;Python+;AWS S3:如何获取特定文件的上次修改属性?

博托+;Python+;AWS S3:如何获取特定文件的上次修改属性?,python,python-2.7,amazon-web-services,amazon-s3,boto3,Python,Python 2.7,Amazon Web Services,Amazon S3,Boto3,可以获取上次修改的属性: import boto3 s3 = boto3.resource('s3') bucket_name = 'bucket-one' bucket = s3.Bucket(bucket_name) for obj in bucket.objects.all(): print obj.last_modified 但它对桶中的所有对象都是如此。如何获取bucket下某个特定对象/文件的last\u modified属性 bucket_name = 'bucke

可以获取上次修改的属性:

import boto3

s3 = boto3.resource('s3')

bucket_name = 'bucket-one'
bucket = s3.Bucket(bucket_name)

for obj in bucket.objects.all():
    print obj.last_modified
但它对桶中的所有对象都是如此。如何获取bucket下某个特定对象/文件的
last\u modified
属性

bucket_name = 'bucket-one'
file_name = 'my_file'

object = s3.Object(bucket_name, file_name)
print object.last_modified
或者简单地说:

print s3.Object(bucket_name, file_name).last_modified

希望这能帮助你

这将获得S3存储桶中特定对象的最后修改时间

import boto3
import time
from pprint import pprint

s3 = boto3.resource('s3',region_name='S3_BUCKET_REGION_NAME')
bucket='BUCKET_NAME'
key='OBJECT_NAME'
summaryDetails=s3.ObjectSummary(bucket,key)
timeFormat=summaryDetails.last_modified
formatedTime=timeFormat.strftime("%Y-%m-%d %H:%M:%S")
pprint( 'Bucket name is '+ bucket + ' and key name is ' + key + ' and last modified at time '+ formatedTime)
谢谢