i new python, , im trying feel language
i have file called lion.txt has text:
the lion (panthera leo) 1 of big cats in genus panthera , member of family felidae. commonly used term african lion collectively denotes several subspecies in africa. males exceeding=250/12 kg (550 lb) in weight,[4].
what want program search keyword exceeding , write value 250 file called searched.txt. @ best possible store variable , print text file?
this have far:
import os import re os.chdir("c:\python 2016 training\lionfolder") f = open("lion.txt", "r") w = open("searched.txt", "w") k = [] #figured dictionary best way deal this? line in f: if re.match('(.*)exceeding(.*)', line): w.write(k[1] = "line")
is im asking possible python?
thank in advance
regards, kevin.
not bad first attempt. you're close working solution, missing critical parts. try this:
import os import re f = open('lion.txt', 'r') w = open('searched.txt', 'w') line in f: match = re.search('exceeding\=(\d+)', line) if match: w.write(match.group(1)) w.close() f.close()
there better ways of doing this, have tried stay close original code possible, don't lost.
Comments
Post a Comment