W
W
wz2021-12-31 19:46:45
Python
wz, 2021-12-31 19:46:45

How to get a specific row and the content in it?

I have given line in .txt file:

VERSION: 0.1.0
NAME: name.
AUTHOR: author.


I need to get exactly the line that starts with the word VERSION and get 0.1.0 or other content in it, regardless of the location of the word VERSION in the code (before NAME, after NAME, etc.). How can i do this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
alexbprofit, 2021-12-31
@rensly

data = {}

for line in open('some.txt', 'r').readlines():
  if line.startswith('VERSION'):
    data[0] = line[9:]

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question