Reading a file

Steven D'Aprano steve at pearwood.info
Sun Feb 15 00:27:53 EST 2009


Philipp Pagel wrote:

> zaheer.agadi at gmail.com wrote:
>> Hi
> 
>> How do i read  a file in Python and search a particular pattern
>> like I have a file char.txt  which has
> 
>> Mango=sweet
>> Sky=blue
> 
>> I want to get the strings sweet and blue,How to do this..?
> 
> If your entire file consists of such key=value pairs you may want to
> properly parse them:

The proper way to parse them would be with the ConfigParser module.

The only negative with ConfigParser is that it requires a section label. In
my experience it is quite common for INI files with only a single section
to leave out the label.


-- 
Steven




More information about the Python-list mailing list