数据打印问题[Python] [关闭]

我知道标题含糊不清,主要是因为我不知道这叫什么。

这是我正在使用的:

from usps import USPSApi
from pprint import pprint as pp

userId = '881STEAD4837'
usps = USPSApi(userId)

trackingNumber1 = input("Enter your tracking number: ")

trackingStatus = usps.track(trackingNumber1).result
trackingResponse = trackingStatus.get('TrackResponse')
trackingInfo = trackingResponse.get('TrackInfo')
trackingError = trackingInfo.get('Error')
trackingId = trackingInfo.get('@ID')

if trackingError is None:
    trackingSummary = trackingInfo.get('TrackSummary')
    trackingDetail = trackingInfo.get('TrackDetail')
    print('Tracking Number {0}'.format(trackingId))
    print('Tracking Summary {0}'.format(trackingSummary))
    print('Tracking Detail:')
    pp(trackingDetail)
else:
    trackingHelp = trackingError.get('HelpFile')
    print('Tracking Number {0}'.format(trackingId))
    print('Tracking Error Description: {0}'.format(trackingError.get('Description')))
    print('Tracking Help: {0}'.format(trackingHelp))

这是我在网上找到的一个简单程序,我希望能够从trackingSummary打印结果的某些部分。

数据格式为:

Tracking Summary {'EventTime': None, 'EventDate': 'April 25, 2020', 'Event': 'In Transit to Next Facility', 'EventCity': None, 'EventState': None, 'EventZIPCode': None, 'EventCountry': None, 'FirmName': None, 'Name': None, 'AuthorizedAgent': 'false'}

我试图提取“跟踪摘要”的某些部分,例如此打印文件(trackingSummary [1]),但显然不起作用。我希望能够打印例如'Event'的值,这样它才可以打印“正在传输到下一个设备”。

评论