creating a list of class instances from file / stdin (AGAIN)

Greg Ewing greg.ewing at compaq.com
Wed Sep 1 00:11:08 EDT 1999


Stephen wrote:
> 
>   What is the syntax to do:
> for line in mb_list:
>     create an instance of this class and append it to a new list????
> Can I combine the mb_list.append statement above to create instances of
> the class while reading the input?

Sure, you can:

  data = []
  for line in mb_program.readlines():
    f1, f2, f3 = string.split(line)
    data.append(MyClass(f1, f2, f3))
    
Hope that helps,
Greg




More information about the Python-list mailing list