如何删除字符串的左侧部分?
发布于 2021-01-29 15:04:08
我有一些简单的python代码,可在文件中搜索字符串,例如path=c:\path
,其中c:\path
部分可能会有所不同。当前代码是:
def find_path(i_file):
lines = open(i_file).readlines()
for line in lines:
if line.startswith("Path="):
return # what to do here in order to get line content after "Path=" ?
什么是获取文字的简单方法Path=
?
关注者
0
被浏览
85
1 个回答
-
从开始
Python 3.9
,您可以使用removeprefix
:'Path=helloworld'.removeprefix('Path=') # 'helloworld'