Hi,
I'm sorry if I wasn't clear enough in the title, don't hesitate to correct it if you find a better way to express that:
I have a file where there are class names, i.e.:
classa
classb
classb
classc
classc
classc
Then I want to read it line by line and to dynamically create that class. I would do something like that in php:
while (!eof())
{
$class=fread(..)
$tab[] = new $class();
}
How would you do that in python (if it's possible)?
Thanks a lot!
Edit: after reading the answers, to be more precise on what I'm planning to do: I'm not planning to do such a simple stuff. It will be far more complex: I want a user who doesn't know programming to edit a simple text file, and to copy/paste some declarations and change their properties and to re-launch a kind of parser which will re-run a batch and show the result of complex operations. Simplified Example of a file:
car:(red,4_wheels,4_places)
bike:(blue,2_wheels,1_place)
Then the user will change it to:
car:(red,4_wheels,4_places)
car:(yellow,4_wheels,2_places)
bike:(blue,2_wheels,1_place)
bike:(green,2_wheels,2_places)
And then with python I'll read this file, create two instances of the class car, and two instances of the class bike. Thus a user who doesn't understand / know python will be able to edit the file without touching a line of code. I think this is the right way to go, if you have any other suggestions for this code, you're welcome!
Olivier Pons