我需要用python格式化下面显示的多行字符串。我试过很多方法,但结果都不好
AMAZON
IPHONE: 700
SAMSUNG: 600
=============
WALMART
IPHONE: 699
===========
ALIBABA
SONY: 500
因此,上述数据代表了在线商店及其品牌手机的价格。我需要将这些添加到数据库中。所以应该是这样
-------------------
AMAZON | IPHONE | 700
-------------------
AMAZON | SAMSUNG | 600
-------------------
WALMART | IPHONE | 699
-------------------
ALIBABA | SONY | 500
-------------------
我需要格式化上面的文本并将其存储在数据库表中
我试过什么? 我尝试拆分多行,创建一个更有可能是JSON的字典。但结局并不好。但它只需要一条线。如果有其他简单的方法,请与我分享。请帮我做这个
@scito提交的答案足够了,但我只是以防万一。 您可以使用regex,下面是一个工作示例:
输出:
数据存储在js列表中,若迭代js,子列表中的第一个元素是market place,其余元素是该market place的产品
我做了一些假设:
工作代码:
输出为:
替代方法:供应商名称也可以作为文本行找到,但不带冒号
相关问题 更多 >
编程相关推荐