python lstrip,rstrip 的 用法

Posted fh-fendou

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了python lstrip,rstrip 的 用法相关的知识,希望对你有一定的参考价值。

#方法一:
import json
s = ‘("freight":["beforeSpecifiedTime":false,"cityCode":"","cityName":"","commitDay":60,"company":"CAINIAO_STANDARD","companyDisplayName":"AliExpress Standard Shipping","coreZone":"","currency":"USD","cutTime":"17:00","deliveryDate":"2019-09-20","deliveryDateDisplay":"other","discount":93,"discountType":"about","domesticFreight":"","errorCode":1,"errorDisplayMsg":"","isCheapestFaster":false,"isDefault":true,"isPromote":false,"isTracked":true,"localCurrency":"USD","localPrice":"0.35","localPriceFormatStr":"US $0.35","localSaveMoney":"5.02","localSaveMoneyFormatStr":"US $5.02","localTotalFreight":"5.37","localTotalFreightFormatStr":"US $5.37","logisticsDeliveryTimeType":"BUYER_PAY_ORDER","notification":"","price":"0.35","priceFormatStr":"US $0.35","processingTime":5,"promoteInformation":null,"remainTime":"-9475079","saveMoney":"5.02","saveMoneyFormatStr":"US $5.02","sendGoodsCountry":"CN","sendGoodsCountryFullName":"China","status":"","templateDiscount":"","templateType":"","time":"22","totalFreight":"5.37","totalFreightFormatStr":"US $5.37","beforeSpecifiedTime":false,"cityCode":"","cityName":"","commitDay":60,"company":"EMS_ZX_ZX_US","companyDisplayName":"ePacket","coreZone":"","currency":"USD","cutTime":"17:00","deliveryDate":"2019-09-19","deliveryDateDisplay":"other","discount":74,"discountType":"about","domesticFreight":"","errorCode":1,"errorDisplayMsg":"","isCheapestFaster":false,"isDefault":false,"isPromote":false,"isTracked":true,"localCurrency":"USD","localPrice":"1.04","localPriceFormatStr":"US $1.04","localSaveMoney":"2.98","localSaveMoneyFormatStr":"US $2.98","localTotalFreight":"4.02","localTotalFreightFormatStr":"US $4.02","logisticsDeliveryTimeType":"BUYER_PAY_ORDER","notification":"","price":"1.04","priceFormatStr":"US $1.04","processingTime":5,"promoteInformation":null,"remainTime":"-9475079","saveMoney":"2.98","saveMoneyFormatStr":"US $2.98","sendGoodsCountry":"CN","sendGoodsCountryFullName":"China","status":"","templateDiscount":"","templateType":"","time":"21","totalFreight":"4.02","totalFreightFormatStr":"US $4.02"])‘
#注意这个s是字符类型的
s1 = s.lstrip(‘(‘) #去除左括号
s = s1.rstrip(‘)‘) #去除右括号
s_dic = json.loads(s) #将字符串转成字典
print(s_dic)

 #方法二:

  使用eval()进行处理。

  

以上是关于python lstrip,rstrip 的 用法的主要内容,如果未能解决你的问题,请参考以下文章

python lstrip,rstrip 的 用法

Python中strip()lstrip()rstrip()用法详解

python中strip(),lstrip(),rstrip()函数的讲解

Lstrip 和 Rstrip 不起作用,需要帮助从 Python 3 的输出中删除文本

ython strip lstrip rstrip使用方法

Python 中strip()方法怎么用?