python - search a word in a file and print only the text betwen two separator -
i'm trying code searching fonction gonna read file , print name it, without other of information on line, found out how print complete line yet..
title = input("\n enter movie name: ") open("data_film") f: line in f: if title in line: print(line)
here file must search in :
1;avatar;science fiction;3;2;3.99 2;little frog;horror;2;3;3.99 ...
so if search title, want check first ";" second ";" movie name , print it.
thanks, hope question clear enought, english not native language.
assuming data file in format, , title after second ';', can use native split function using semicolon delimiter. splits line @ semicolons array, , title second element.
title = input("\n enter movie name: ") open("data_film") f: line in f: if title in line: print(line.split(';')[1])
Comments
Post a Comment