Parsing & question about usages off classes!

Greg Ewing see_reply_address at something.invalid
Sun Nov 3 17:57:33 EST 2002


Frans wrote:

> 
> So I thought I would do the following:
> 
> short=['D','H','W']
> long=['DAILY','HOURLY','WEEKLY']
> 
> information = string.split(logline,'\t')   
> 
> DAILY.append(information)


Use a dictionary indexed by the first field in the log line.
For example:

   log_dict = {} # Create an empty dictionary
   log_dict['D'] = [] # Initialise with 3 new empty lists
   log_dict['H'] = []
   log_dict['W'] = []

   ...
         # for each log line:
         information = string.split(logline,'\t')
         log_dict[information[0]].append(information)

Then log_dict['D'] will contain a list of all the log entries
beginning with 'D', etc.

If you really want them in separate variables, you could then
do

    DAILY = log_dict['D']
    HOURLY = log_dict['H']
    WEEKLY = log_dict['W']

-- 
Greg Ewing, Computer Science Dept,
University of Canterbury,	
Christchurch, New Zealand
http://www.cosc.canterbury.ac.nz/~greg




More information about the Python-list mailing list