Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to extract a text in a file python

Tags:

python

How to extract a text in a file with python. - A text begin with chaine.

My code is

fichier= open("Service.txt", "r")
for ligne in fichier:
  if ligne==chaine:
  #What do I do ? 
fichier.close()
like image 812
HICHEM Avatar asked Feb 11 '26 10:02

HICHEM


1 Answers

If I understood question correctly:

test.txt

fsdfj ljkjl
sdfsdf ljkkk
some ldfff
fffl lll
ppppp

script:

chaine = 'some'

with open("test.txt", "r") as f:
    text = f.read()
    i = text.find(chaine)
    print(text[i:])

output:

some ldfff
fffl lll
ppppp
like image 120
Mikhail Gerasimov Avatar answered Feb 18 '26 15:02

Mikhail Gerasimov