【发布时间】:2022-08-11 19:19:51
【问题描述】:
我是python新手,想将recentAveragePrice存储在一个变量中(来自像这样的字符串)
{\"assetStock\":null,\"sales\":250694,\"numberRemaining\":null,\"recentAveragePrice\":731,\"originalPrice\":null,\"priceDataPoints\":[{\"value\":661,\"date\":\"2022-08-11T05:00:00Z\"},{\"value\":592,\"date\":\"2022-08-10T05:00:00Z\"},{\"value\":443,\"date\":\"2022-08-09T05:00:00Z\"}],\"volumeDataPoints\":[{\"value\":155,\"date\":\"2022-08-11T05:00:00Z\"},{\"value\":4595,\"date\":\"2022-08-10T05:00:00Z\"},{\"value\":12675,\"date\":\"2022-08-09T05:00:00Z\"},{\"value\":22179,\"date\":\"2022-08-08T05:00:00Z\"},{\"value\":15181,\"date\":\"2022-08-07T05:00:00Z\"},{\"value\":14541,\"date\":\"2022-08-06T05:00:00Z\"},{\"value\":15310,\"date\":\"2022-08-05T05:00:00Z\"},{\"value\":14146,\"date\":\"2022-08-04T05:00:00Z\"},{\"value\":13083,\"date\":\"2022-08-03T05:00:00Z\"},{\"value\":14460,\"date\":\"2022-08-02T05:00:00Z\"},{\"value\":16809,\"date\":\"2022-08-01T05:00:00Z\"},{\"value\":17571,\"date\":\"2022-07-31T05:00:00Z\"},{\"value\":23907,\"date\":\"2022-07-30T05:00:00Z\"},{\"value\":39007,\"date\":\"2022-07-29T05:00:00Z\"},{\"value\":38823,\"date\":\"2022-07-28T05:00:00Z\"}]}
我目前的解决方案是这样的:
var = sampleStr[78] + sampleStr[79] + sampleStr[80]
它适用于当前字符串,但如果 recentAveragePrice 高于 999 它将停止工作,我想知道是否可以在字符串中搜索它而不是获得一个固定数字。
-
sampleStr是什么? -
请分享您尝试过的完整代码,否则我们只是猜测。
-
您确定要处理字符串而不是字典吗?
-
我在共享代码时遇到问题,但它在此复制页面中 replit.com/@ShyMike/8-Bit-Collection-Profit#main.py
标签: python python-3.x string variables search