如何在python中生成第一个文件路径

2024-04-29 07:42:51 发布

您现在位置:Python中文网/ 问答频道 /正文

我总是对正则表达式感到头痛,但我想这可能是一种方法。这是我的字符串:

-rw-rw----+  3 userabc clouderausersdev   12267543 2018-02-05 16:41 hdfs://nameservice1/client/abc/scenarios/warehouse/product/tdb_histscen_2/part-00000-6fa2e019-96e5-4280-b2fc-994917013a6a-c000.snappy.parquet

我只想显示文件的完整路径:

hdfs://nameservice1/client/abc/scenarios/warehouse/product/tdb_histscen_2/part-00000-6fa2e019-96e5-4280-b2fc-994917013a6a-c000.snappy.parquet

非常感谢。你知道吗


Tags: nameclientservicehdfsproductwarehouserwabc
1条回答
网友
1楼 · 发布于 2024-04-29 07:42:51

为什么不直接取空格分隔字符串的最后一个值呢?你知道吗

x = "-rw-rw  +  3 userabc clouderausersdev   12267543 2018-02-05 16:41 hdfs://nameservice1/client/abc/scenarios/warehouse/product/tdb_histscen_2/part-00000-6fa2e019-96e5-4280-b2fc-994917013a6a-c000.snappy.parquet"
parts = [y for y in x.split(' ') if y]  # removes empty strings
fname = parts[-1]

相关问题 更多 >