Game Programming and Development Tools

Python Script reading in C++ – dartsman

dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
Hey ppl...

I don't know python, haven't used it, most prolly wont. But at work I was asked a question about how to load up and read Python Scripts in C++. Is there a library to download to which would help the student?

It's so that he could load up the python scripts into his program and use the data in them to run the game. I think he was saying that he is using pygame or something to test the python scripts. I'm guess what he wants to do is a pygame type application which he can use.

Anywho, thanks in advance...

------------------
"But it is God who judges: He brings one down, he exalts another." - Psalm 75:7

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
i know that it's possible to do that... i don't know exactly how tho. i've googled it a bunch of times... sorry i can't be of much help.

------------------
WARNING:

RADIOACTIVE IE AHEAD!
--------------------
#include <spazz.h>

int name()
{
char name['B','u','d','d','B','o''y']

CoolJ

Member

Posts: 354
From: ny
Registered: 07-11-2004
Though I don't use it much, I absolutely love python! I think the default answer with anything you want to do with python is 'YES' For using python scripts in C++, you might want to check here to start:

http://docs.python.org/ext/embedding.html

From their docs:

quote:

There are several different ways to call the interpreter: you can pass a string containing Python statements to PyRun_SimpleString(), or you can pass a stdio file pointer and a file name (for identification in error messages only) to PyRun_SimpleFile(). You can also call the lower-level operations described in the previous chapters to construct and use Python objects.

A very simple example from the docs:

quote:

#include <Python.h>

int
main(int argc, char *argv[])
{
Py_Initialize();
PyRun_SimpleString("from time import time,ctime\n"
"print 'Today is',ctime(time())\n");
Py_Finalize();
return 0;
}



I think you will find python to be simple yet very powerful. Its a fun language!

[This message has been edited by coolj (edited June 22, 2006).]

dartsman

Member

Posts: 484
From: Queensland, Australia
Registered: 03-16-2006
thanks coolj, I'll let the guy know next time I see him, hopefully sooner rather then later. I think it's for an assignment of his, so he doesn't have too much time left.

------------------
"But it is God who judges: He brings one down, he exalts another." - Psalm 75:7

buddboy

Member

Posts: 2220
From: New Albany, Indiana, U.S.
Registered: 10-08-2004
where do you get Python.h? does it come with the interpreter?


[edit] oh ok nvm. [/edit]

------------------
WARNING:

RADIOACTIVE IE AHEAD!
--------------------
#include <spazz.h>

int name()
{
char name['B','u','d','d','B','o''y']

[This message has been edited by buddboy (edited June 24, 2006).]