[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Loading commands from a file



"Ian Mallett" <geometrian@xxxxxxxxx> wrote:

> I'd like to know how to load commands from a file.  In the file (in this
> case a .txt) there would be commands like "glBegin(GL_QUADS)".  I would
> like
> to load these commands into a program so that the commands can be
> executed.
> Previously, I had been selecting all in the .txt file and pasting all in
> the
> .py file, but I think there must be a better way.

This is more of a python question than a pygame question.

Two possibilities suggest themselves - assuming you have the commands in a
file called "textcommands.txt":

Possibility 1:
import shutil
shutil.copyfile("cmd.txt","textcommands.py")
import textcommands


Possibility 2 (see http://docs.python.org/ref/exec.html)
exec file("textcommands.txt").read()


-Dave LeCompte