create/access dynamic growth list
Larry Bates
lbates at syscononline.com
Fri Mar 18 09:59:19 EST 2005
sam wrote:
> Hi,
>
> I have a configuration file need to be processed (read/write) by python.
> Currently I the following method can only read and store data that
> python read a line from a configuraiton file:
> def _parse (self):
> # parse message
> m = self.FWShow_Command.match (conf_data)
> if (m == None):
> raise FW_Command.Error ("corrupt macro definition")
>
> # store generic data
> macro = {}
> macro["key"] = m.group (1)
> macro["value"] = m.group (2)
>
> return (conf_data, macro)
>
> Since there are unknown number of lines in a configuration file, I want
> to store the array of "macro" in a list.
> How can I do that in Python?
>
> Thanks
> Sam.
Pretty sketchy description, but I'll take a shot.
fp=open(conf_data, 'r')
macro_lines=fp.readlines()
fp.close()
After this macro_lines will be a list with one line per element
such that macro_list[0] is the first line, macro_list[1] the
second, etc.
Larry Bates
More information about the Python-list
mailing list