473,721 Members | 2,205 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Python script and C++

Hi all,

I am new to python and currently I am working on a traffic simulation
which I plan to define the various agents using scripting. It's kind of like
scripting for non-playable character in games. I am thinking of using python
for this but I am concerned with running time. Is scripting a lot slower
compared to direct implementation in C++? Does compiling the script help in
any way? Also, can anyone recommend me a book that covers python in general
as well as C++ binding? Thanks.
Thuan Seah Tan
Nov 28 '06 #1
5 1525
Thuan Seah Tan wrote:
Hi all,

I am new to python and currently I am working on a traffic simulation
which I plan to define the various agents using scripting. It's kind of like
scripting for non-playable character in games. I am thinking of using python
for this but I am concerned with running time. Is scripting a lot slower
compared to direct implementation in C++? Does compiling the script help in
"Learning Python" is a good book to start learning Python. I don't think
you'll be better off in C++. If speed is of utmost importance for the
whole implementation, then I suggest C++ but well coded Python runs
atleast/near to C++ implementation. Otherwise, you can atleast code the
speed-savvy part of the implementation in C++. Ofcourse, Python object
model is based on a virtual machine (called PVM) which accounts for
slower start-up due to native function call conversion but you'll find
that learning curve is only a tiny fraction compared to C++. And you'll
surely love Python. =)
any way? Also, can anyone recommend me a book that covers python in general
as well as C++ binding? Thanks.
"Progamming in Python" is another excellent book that might be of help.
If you are developing on windows machine then
http://aspn.activestate.com/ASPN/Python has some helpful recipes.

C++ bindings in Python are handled by extending python objects and
manipulating it from C++ codes using the Python headers.

Also, http://python.org/docs should be a good reference.
Also Google for "vaults of parnassus" and Fredrik lundh's guide on Python.

Goodluck!
--
thanks,
nepBabu.cx
c c
.-.,;(")
..'`~C.-.c =W=

Nov 28 '06 #2
Thuan Seah Tan wrote:
Hi all,

I am new to python and currently I am working on a traffic simulation
which I plan to define the various agents using scripting. It's kind of like
scripting for non-playable character in games. I am thinking of using python
for this but I am concerned with running time. Is scripting a lot slower
compared to direct implementation in C++? Does compiling the script help in
any way? Also, can anyone recommend me a book that covers python in general
as well as C++ binding? Thanks.
Even if pure python turns out to be slow for some critical parts of
your application, there are quite a few ways to deal with it: psyco,
pyrex, weave/blitz, ctypes, SWIG, Boost-python, SIP, CXX, SCXX,
hand-written C extensions and perhaps more. Visit
http://www.scipy.org/PerformancePython for an example of taking a
simple pure Python function and boosting it using several different
tools. Check out the final comparison table first; the pyrex version is
less than half a second slower than the C++.

George

Nov 28 '06 #3
Thuan Seah Tan wrote:
Hi all,

I am new to python and currently I am working on a traffic simulation
which I plan to define the various agents using scripting. It's kind of like
scripting for non-playable character in games. I am thinking of using python
for this but I am concerned with running time. Is scripting a lot slower
compared to direct implementation in C++? Does compiling the script help in
any way?
Python is perfectly suitable for this use. Python was in use in video
games in this way when computers were a lot slower. I doubt that you
will need to bother compiling the script or see any observable
enhancement if you do.

One example I can remember is Kingdom Under Fire (2001).

Nov 28 '06 #4
In <11************ **********@n67g 2000cwd.googleg roups.com>, Ravi Teja
wrote:
> I am new to python and currently I am working on a traffic simulation
which I plan to define the various agents using scripting. It's kind of like
scripting for non-playable character in games. I am thinking of using python
for this but I am concerned with running time. Is scripting a lot slower
compared to direct implementation in C++? Does compiling the script help in
any way?

Python is perfectly suitable for this use. Python was in use in video
games in this way when computers were a lot slower.
There's a difference between simulations and games. The simulation will
not always be observed by a human being so it runs as fast as possible.
In games the speed of NPCs is usually limited to a level the player can
deal with.

But I think Python is fine for such a task. The only way to find out if
it may be to slow is writing a prototype and measure. Maybe it's a good
idea to design the API for the "NPCs" independent from the language so you
can also write them in C++ or another scripting language.

Ciao,
Marc 'BlackJack' Rintsch
Nov 28 '06 #5
On Tue, 28 Nov 2006 10:12:23 +0100, Marc 'BlackJack' Rintsch <bj****@gmx.net wrote:
In <11************ **********@n67g 2000cwd.googleg roups.com>, Ravi Teja
wrote:
>> I am new to python and currently I am working on a traffic simulation
which I plan to define the various agents using scripting. It's kind of like
scripting for non-playable character in games. I am thinking of using python
for this but I am concerned with running time. Is scripting a lot slower
compared to direct implementation in C++? Does compiling the script help in
any way?

Python is perfectly suitable for this use. Python was in use in video
games in this way when computers were a lot slower.

There's a difference between simulations and games. The simulation will
not always be observed by a human being so it runs as fast as possible.
In games the speed of NPCs is usually limited to a level the player can
deal with.
Yeah. Simulation can mean running for a week on the best hardware available,
with the most optimized code you can come up with. And a week may be
acceptable, while two weeks are not.
But I think Python is fine for such a task.
I am not so sure, but ...
The only way to find out if
it may be to slow is writing a prototype and measure.
.... this is a good approach.
Maybe it's a good
idea to design the API for the "NPCs" independent from the language so you
can also write them in C++ or another scripting language.
However, if that API requires thousands of calls per second during
simulation time, it doesn't help speed much, because calling C code from
Python is a pretty heavy thing in itself. The big win is when you spend a
lot of uninterrupted CPU time in C code.

One approach is to write the executive engine in C++ (once again: if needed)
and the compiler/configuration subsystem -- the thing that generates the
simulated world -- in Python. That's a perfect place for a flexible,
high-level language.

/Jorgen

--
// Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
\X/ snipabacken.dyn dns.org R'lyeh wgah'nagl fhtagn!
Nov 28 '06 #6

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

Similar topics

28
4611
by: Erik Johnson | last post by:
This is somewhat a NEWBIE question... My company maintains a small RDBS driven website. We currently generate HTML using PHP. I've hacked a bit in Python, and generally think it is a rather cool language. I've done Perl and like it, there are a few features of PHP I like but overall am not too excited about it. I have found PHP's strtotime() function to be quite flexible and handy and we make liberal use of it. I have not yet really...
2
4901
by: DeepBleu | last post by:
When one is using an HTML form via a web broswer, the user submits the form contents and these are passed to a CGI Python script on the web server. I need to write a client script that connects to a web site, runs a Python CGI script on the web server AND passes a string to the CGI Python script that the Python CGI script can store/manipulate/evalute etc.... I know how to connect to the web site and run the CGI Python script using a client...
52
3758
by: Olivier Scalbert | last post by:
Hello , What is the python way of doing this : perl -pi -e 's/string1/string2/' file ? Thanks Olivier
4
3274
by: Tom Purl | last post by:
I just wrote a Python script that is going to be called from bash script. If the Python script fails, I want the bash script to also stop running. Unfortunately, I can't seem to get that to work. Here's the script so far: # custom python script /usr/bin/python /home/username/Dev/Python/packZODB.py \ -s"gsgmc.sigma.zettai.net" -b 7 # next program
17
3870
by: Paul Rubin | last post by:
Dumb question from a Windows ignoramus: I find myself needing to write a Python app (call it myapp.py) that uses tkinter, which as it happens has to be used under (ugh) Windows. That's Windows XP if it makes any difference. I put a shortcut to myapp.py on the desktop and it shows up as a little green snake icon, which is really cool and Pythonic. When I double click the icon, the app launches just fine and the tkinter interface does...
9
2078
by: TPJ | last post by:
First I have to admit that my English isn't good enough. I'm still studying and sometimes I just can't express what I want to express. A few weeks ago I've written 'Python Builder' - a bash script that allows anyone to download, compile (with flags given by user) and install Python and some external modules (e.g. wxPython, PyGTK, Numeric...). I use Python every day and when new version of Python (or some external module) is released, I...
3
2610
by: krzychu | last post by:
Hi, I have installed brand new platform - Zope-2-7-6, Python 2.4.1, Plone 2.0.5, OS Debian 1:3.3.6-2. After import a old Plone site from the following platform Zope-2-7-4, Python 2.3.3, Plone 2.0.3 to the new one, I get error when I visit PuthonScript in the ZMI. "invalid syntax (Script (Python), line 1)"
6
7496
by: manatlan | last post by:
I've got a trouble, and i think that anybody there can help me I've got a python script which i distribute in somes packages for *nix. This script is full of python and need python 2.4 ! And i'd like to display a message when the user doesn't have a python2.4 version. if i put, at the top of the script (which can be done with /usr/bin env too): #/usr/bin/python2.4
37
2496
by: John Salerno | last post by:
I contacted my domain host about how Python is implemented on their server, and got this response: ------------------- Hello John, Please be informed that the implementation of python in our server is through mod_python integration with the apache. These are the steps needed for you to be able to run .py script directly
6
9939
by: tatamata | last post by:
Hello. How can I run some Python script within C# program? Thanks, Zlatko
0
8860
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9234
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9150
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9086
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8028
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6678
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5994
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4762
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2599
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.