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:
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=" ?
What is a simple way to get the text after Path=
?
Advertisement
Answer
Starting in Python 3.9
, you can use removeprefix
:
'Path=helloworld'.removeprefix('Path=') # 'helloworld'