I have some simple python code that searches files for a string e.g. path=c:path
, where the c:path
part may vary. The current code is:
JavaScript
x
6
1
def find_path(i_file):
2
lines = open(i_file).readlines()
3
for line in lines:
4
if line.startswith("Path="):
5
return # what to do here in order to get line content after "Path=" ?
6
What is a simple way to get the text after Path=
?
Advertisement
Answer
Starting in Python 3.9
, you can use removeprefix
:
JavaScript
1
3
1
'Path=helloworld'.removeprefix('Path=')
2
# 'helloworld'
3