python - 如何将字符串分解为多个换行符?
问题描述
我有亚马逊订单的详细信息,文字字符串由换行符 \n 分隔。
str = 'Linon Hampton Stool Fabric Top, 24-inch \nSold by: Amazon.com Services, Inc \n$33.99'
我想为每个新行将其拆分为 n 个字符串,使其看起来像。
str1 = 'Linon Hampton Stool Fabric Top, 24-inch'
str2 = 'Sold by: Amazon.com Services, Inc '
str3 = '$33.99'
解决方案
使用split
. 它将以列表的形式为您提供输出:
string = 'Linon Hampton Stool Fabric Top, 24-inch \nSold by: Amazon.com Services, Inc \n$33.99'
string.split("\n")
并且不要给你的变量 name str
。它是一个内置函数名称。
推荐阅读
- android - 除带有彩色操作系统的 OPPO 外,服务在所有手机上都能正常工作。在 oppo 中,服务会持续运行一段时间,但随后停止工作。有什么解决方案吗?
- http - 如何使用 http 而不是 https 在 Heroku 上提供 Golang 应用程序?
- c++ - 在qt中通过鼠标拖动滚动
- admin - Hyperledger Composer PeerAdmin 网络管理员集中化?
- python - 使用 gml 文件中的多边形遮罩栅格的最快方法
- php - GoDaddy 上的 Laravel artisan 不接受任何数据库用户,为什么?
- android - 如何使用android开发中的下载链接从Firebase存储下载pdf文件
- rabbitmq - RabbitMq 集群如何帮助可扩展性?
- android - 在以前的活动中从 firestore 快照侦听器中杀死所有其他活动
- python-3.x - 形成集群时获取函数中的索引错误