So I've been meaning to blog Python code for use in VBA for some time. This month, I'm going to specialise on Python.
Python is mature and open source; and has rich ecosystem
So Python was created in 1991 (which usefully gives it a similar vintage to COM), Python is thus mature. Python is open source and so its bug are fixed; and given Python's age, many of its libraries have had plenty of time for the community to find and fix any bugs. Also, as a mature open source technology, Python has developed a rich ecosystem. One can find a library for pretty much anything in Python. The only downside perhaps is that it can sometimes feel like there are too many choices!
VBA's Tools->References Libraries don't change much
There is only so much an Excel VBA developer can do with libraries found in the Tools->References dialog. The population of COM libraries does not increase very much. Of course, one can use C# and the .NET development platform and wrap the code in a COM interface, and you will find examples of that on this blog. One can even use C++ to wrap the Windows software development kit and again ship a COM interface using ATL. But fundamentally, we need to break out of the Tools->References dialog box.
The COM Class Gateway To Python
As can be found in this blog post it is possible for Python to expose an a COM interface and whilst the example given does not ship a type library and thus will not appear in the VBA Tools->References dialog box the code will be perfectly executable if using late binding. This means we can use this COM Class mechanism as a gateway to Python's ecosystem.
Coming up in this Python month
In this month, I would like to publish code for the following Python use cases...
- Arbitrary-precision arithmetic - whilst VBA has fixed limits for integers, Python can handle extremely large numbers
- SciPy - use the scientific library; for example factorise quadratic equations
- Cryptography - related to Arbitrary-precision arithmetic (see above) Python has the capacity to encrypt and decrypt using very long encryption keys
- OAuth2 - write applications that talk to web apis which require logons
- Curve building - in finance application it is often required to smooth data such as a term structure of interest rates (yield curve) or 'jagged' stock market data
- Machine learning - a field of computer science that often uses statistical techniques to give computers the ability to "learn"
What Python version are you using? (My latest attempts with 3.11 seem very problematic, the simple examples work, but the more involved ones fail with the usual thoughtfully truncated diagnostics)
ReplyDelete