Overcoming Potential Extension Problems
❘
435
➤
➤
Python for Windows: A number of extensions specifically designed for Windows developers
that are packaged together (some developers might know this package as pywin32). You can
download this package from
http://sourceforge.net/projects/pywin32/
. The majority
of this package will very likely run without extra help.
There are some situations where you should consider not using an extension. For example, you could
easily download the
pymssql
extension found at
http://pymssql.sourceforge.net/
. However,
it’s probably easier to write your own extension using Visual Basic.NET using the technique shown in
Chapter 17. The resulting extension will probably run faster and provide precisely what you need with
a lot less work. For that matter, you could always decide to import the required .NET assemblies and
directly access your database from IronPython (assuming you want to pursue the task without designer
support). When in doubt, consider at least trying to obtain the results you want using the simplest and
most direct approach possible, which often means writing your own extension.
OvErcOmINg POTENTIAl EXTENSION PrOblEmS
If you have a CPython extension that you really must use and there isn’t an IronPython alternative,
you have a number of solutions you can try. Of course, the first solution is to get someone else to fix
the problem (see the section “Obtaining Third-Party Solutions” later in this appendix for details).
Unfortunately, duping someone else into performing your work for you isn’t always possible, so you
might have to fix the problem yourself.
When you have the source code for the CPython extension in the form of a
.py
file, you can some-
times fix the issue directly. Try importing the extension and then working with it. Often, the error
information you receive from the interpreter is enough to help you locate and fix the problem. Some
CPython extensions will work fine once you overcome the compatibility issues between IronPython
and CPython.
One company that has a lot of experience fixing problem extensions is
Resolver Systems. You’ll find blogs and articles about the experiences of
their developers in a lot of places on the Internet. Most important, Resolver
Systems has created a spreadsheet application, Resolver One, which relies
on IronPython as its base language. You can learn more about Resolver
Systems at
http://www.resolversystems.com/
. Another example of Python
in action is the Python Extension for Mozilla developers found at
http://
pyxpcomext.mozdev.org/
. You get the power of Python within Firefox,
Thunderbird, and XulRunner. In short, there are lots of examples of Python
in use on the Internet.
The issue that will give you the most trouble is that some CPython extensions rely on C code. These
extensions contain a combination of Python code and DLLs written in C because using C provides
certain advantages (much as C# and Visual Basic.NET provide certain advantages for the .NET
548592bapp02.indd 435
2/24/10 12:50:02 PM
www.finebook.ir
Do'stlaringiz bilan baham: |