Python in a VS 6.0 environment?

David Brady dbrady at computer.org
Thu Feb 6 17:45:38 EST 2003


On Thu, 2003-02-06 at 13:40, Brandon Van Every wrote:
> Can anyone who prefers a MS Visual Studio 6.0 working environment comment on
> the ease / difficulty of integrating Python with your C++ code?  What are
> the gotchas?  I'd like to know what tools have made the experience the least
> painful for you.

I was never able to truly integrate Python with DevStoo at the
interpreter level (as in, a replacement for VBScript macros in the
editor), but at my last job I used Python a TON for helping with my C++
code.

This generally fell into 2 categories:

1. Keep PythonWin running all the time, and tab over to it whenever you
need a quick calculation, or to emit a function template.  If somebody
handed me a list of 20 identifiers to add to a program, I'd go straight
to Python, write them out as a list, then write a function to emit the
declarations, initializers, etc.  Clipboard them into DevStoo and go.

2. Python as an external build tool.  It's been 9 months since I coded
heavily on the Win32 platform, so I can't remember EXACTLY how we did
this, but you can use Python as a "pre-compiler step" for a file.  For
example, we had a message database that had to be shared between
projects.  I wrote a text file containing all the messages (ID,
description) and a Python script that could read it and emit the .h and
.cpp files for it.  Some key things I remember:

* Play around with dependencies, and make the .h/.cpp file depend on the
.db file.  You can get DevStoo to rebuild the .h/.cpp files
automagically if their mod date is older than the .db file.  This is
bone-jarringly simple in makefiles, but at the time it was a revelation.

* Have your Python script emit warnings and errors in the same format as
DevStoo's C++ warnings an errors.  If the string contains the word
"warning" it will increase the compiler's warning count; same for
"error".  Also, if you emit the warning/error starting with
c:\path\path\file(line): you will be able to double-click on the
error/warning line and have DevStoo warp you to that file and line.

* You may have to print to stderr rather than stdout to get DevStoo to
capture your warnings.  I don't think so, but maybe.  As I said, I'm
going from old and rotting memories.  :-)  Be prepared to play around
w/it.

Good luck!

-dB






More information about the Python-list mailing list