Can I create object names from a text file in Python 2.7?

Posted by user560100 on Stack Overflow See other posts from Stack Overflow or by user560100
Published on 2011-01-02T03:35:05Z Indexed on 2011/01/02 3:54 UTC
Read the original article Hit count: 360

I'm working on a game project. I've created an object, Star(Object). I want to assign the name of the variables, dynamically, from a text file.

If I have a text file with: Sol Centauri Vega

I want the program to create the Star(Object) with variable names from the text file. I want the process automated, because I'm looking to create hundreds of stars. I could write the code out by hand: Sol = Star(Sol) Centauri = Star(Centauri) Vega = Star(Vega)

But isn't there a way to automate this?

Essentially, what I eventually want is a tuple with the list of stars, as their own objects. Then, when I am doing game maintenance, I can just iterate over all the objects in the tuple.

© Stack Overflow or respective owner

Related posts about python

Related posts about game-development