473,387 Members | 1,485 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Creating Modules/Namespaces from C/C++ for better class/function encapsulation/cleanup

Hi folks!

The problem is the following:

I use Python 2.1 embedded in a C++ game engine. Some of the engines
complexer objects (AI, game logic, etc.) use python classes that act as
an extension of those "parent" C++-classes.

The python classes are currently loaded on demand by their "parent"
C++-instances, say if an enemy gets activated and starts running. I do
that by:
1.) reading the needed python script (dedicated to that enemy class)
into a string and then
2) calling 'Py_CompileString()' followed by
3) 'PyEval_EvalCode()'

Then I have access to all class(es) defined in the python script
implementing all the needed methods for my enemy.
It looks a bit tedious than just calling e.g. 'PyRun_SimpleFile()', but
I thought, that PyEval_EvalCode() could provide me with means to force
a local and global namespace on the interpreted code.

Problem and Question:
To get rid of ALL code/class definitions/etc. defined when I loaded and
interpreted the enemy's python script, I want the python interpreter to
force a namespace or module context on everything associated with my
enemy, so I can be sure I cleaned up everything that is related to the
previous loading operation. I tried to use a new module (e.g. calling
'PyImport_AddModule') as my local namespace, but the script couldn't
find any built-in functions or even other classes defined in the very
same script file anymore when I did that.

Any idea how to do that properly?

Cheers!

PiLLe

Jul 18 '05 #1
0 1253

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Dan Bishop | last post by:
I installed Python on the HP 3000 at work today. The interpreter itself appears to be working fine, but "import math", "import datetime", etc. fail with "ImportError: No module named ". ...
30
by: Sean R. Lynch | last post by:
I've been playing around with Zope's RestrictedPython, and I think I'm on the way to making the modifications necessary to create a capabilities-based restricted execution system. The idea is to...
4
by: Chuck Ritzke | last post by:
I keep asking myself this question as I write class modules. What's the best/smartest/most efficient way to send a large object back and forth to a class module? For example, say I have a data...
31
by: N.Davis | last post by:
I am very new to Python, but have done plenty of development in C++ and Java. One thing I find weird about python is the idea of a module. Why is this needed when there are already the ideas of...
9
by: kermit | last post by:
I keep seeing that you can use the FileSystemObject in either VB script, or Javascript on an aspx page. I added a refrence to the scrrun.dll I added importing namespaces for 'System.Object',...
3
by: Chris B. | last post by:
I'm getting some strange results in an asp.net web application that has recently gone live. In the header of almost all the pages, the full name of the currently logged in user is displayed. On...
5
by: Erik Cruz | last post by:
Hello! I have read some threads discussing the fact that a module is in reality a shared class. If I try to create a Public Shared Class in vb.net I receive a compile error. Why? If I can't...
5
by: Alex | last post by:
Hi, this is my first mail to the list so please correct me if Ive done anything wrong. What Im trying to figure out is a good way to organise my code. One class per .py file is a system I like,...
2
by: FFrozTT | last post by:
I am having a problem creating a DLL with an entry point. I've been trying sub Main, DllMain, and I get nothing. When I run dumpbin - exports mydll.dll I see no entry points, also the dll when...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.