gpt4 book ai didi

python - 从 python 字符串中切片消息

转载 作者:太空宇宙 更新时间:2023-11-04 10:32:04 25 4
gpt4 key购买 nike

我正在检索字符串格式的错误消息。我必须从中切出消息。我试过将它转换成一个列表,但那是将整个消息放入单独的列表中。尝试了 python 子字符串/切片但无法检索消息。

错误信息是这样的

    (vmodl.fault.InvalidArgument) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
msg = 'A specified parameter was not correct. \nspec.name',
faultCause = <unset>,
faultMessage = (vmodl.LocalizableMessage) [
(vmodl.LocalizableMessage) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 'com.vmware.vim.vpxd.dvs.uniqueField1.label',
arg = (vmodl.KeyAnyValue) [
(vmodl.KeyAnyValue) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 'dvs1',
value = 'ExampleDVS1'
},
(vmodl.KeyAnyValue) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 'prop',
value = 'spec.name'
},
(vmodl.KeyAnyValue) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 'value',
value = 'ExampleDVS1'
},
(vmodl.KeyAnyValue) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 'op',
value = 'create'
},
(vmodl.KeyAnyValue) {
dynamicType = <unset>,
dynamicProperty = (vmodl.DynamicProperty) [],
key = 'dvs2',
value = 'ExampleDVS1'
}
],
message = 'A VDS ExampleDVS1 with spec.name as ExampleDVS1 already exists, cannot create VDS ExampleDVS1'
}
],
invalidProperty = u'spec.name'
}

如您所见,有一个消息字段,我想将其检索为 'A VDS ExampleDVS1 with spec.name as ExampleDVS1 already exists, cannot create VDS ExampleDVS1'

最佳答案

试试这个:

re.search(r"message\s+=\s+'([^']*)'",text_string,re.M).group(1)

关于python - 从 python 字符串中切片消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25801761/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com