Parsing Text file

Neil Cerutti neilc at norwich.edu
Tue Jul 2 16:12:55 EDT 2013


On 2013年07月02日, Tobiah <toby at tobiah.org> wrote:
> On 07/02/2013 12:30 PM, sas429s at gmail.com wrote:
>> Somemore can be anything for instance:
>>>> Sometext
>> mail
>> maskit
>>>> Sometext
>> rupee
>> dollar
>> maskit
>>>> and so on..
>>>> Is there a way I can achieve this?
>> How do we know whether we have Sometext?
> If it's really just a literal 'Sometext', then
> just print that when you hit maskit.
>> Otherwise:
>>> for line in open('file.txt').readlines():
>> 	if is_sometext(line):
> 		memory = line
>> 	if line == 'maskit':
> 		print memory

Tobiah's solution fits what little we can make of your problem.
My feeling is that you've simplified your question a little too
much in hopes that it would help us provide a better solution.
Can you provide more context? 
-- 
Neil Cerutti


More information about the Python-list mailing list

AltStyle によって変換されたページ (->オリジナル) /