file - How to search phrases in a string in python -


i change text file string. string has been formatted like

{'au': 'smith, s’}, {'au': 'james, a’}, {'au': 'stevens, p’} 

i used code try , find number of times name appears in data. however, returned actual original string. there anyway fix this?

searchfile = open('file.txt', 'r') line in searchfile:      if 'author name' in line: print (line) searchfile.close() 

what print 'author name'

searchfile = open('test', 'r') word = "test" lst = [] line in searchfile:     = line.split()     x in a:         if x == word:             lst.append(x) print(lst)   searchfile.close() 

this took little bit of research , testing, should wanted :). line.split() put words separated space in text file list. there, cycle through list checking if matches world. if does, push our list , later on print can see.

if searching smith example "'smith," because there's no space separating ' , , smith unless want make function removes : , ' { }.


Comments

Popular posts from this blog

mysql - Dreamhost PyCharm Django Python 3 Launching a Site -

java - Sending SMS with SMSLib and Web Services -

java - How to resolve The method toString() in the type Object is not applicable for the arguments (InputStream) -