I have written a python wrapper for a c dll.
I now wish to interact with this wrapper from an ASP classic script, served online via IIS7.
How would you recommend I do this?
If it's a Python wrapper, you need Python to use it. You can use Python as a scripting language from ASP, I recommend activestate's Python distribution, because it integrates with Windows and IIS by default.
You should be able to write an ASP page in Python and load your library in it.
Here is more info on using Python from ASP.
It should even be possible to write a page in VBscript and call a piece of Python code in a Python WSC (Windows Scripting Component). I have researched this a great deal, it works, but if you want to do this you can only pass simple data types from one language to the other (strings, booleans, numbers)
Related
I've just started learning a bit of Python and I'm currently trying to implement a Python UI through HTML. Is there anything in vanilla Python that would allow for this, similar to how you can create UI's with Java and XML with JFX or will I have to use a framework such as Django?
I'm reluctant to use Django as there are many features that I do not need
Thanks,
Michael
In vanilla python wsgiref is very helpful for building the server-side of web-applications (possibly with str.format or string.Template and/or json) but if you want it more direct communication I would suggest XML-RPC (there are good js-clients out there).
It is also possible to execute Python Scripts right in your Website with Brython or (with strong constraints) Ironpython
For Windows you can build HTML Applications with Ironpython (have not tried but in theory it should work) or Brython (if you dont want to require the user to have ironpython installed)
You can also use Pyjs to build applications but while it uses html and javascript, i think it you dont see much of it.
There are HTML things in some ui-libraries like in wxpython (I am quite sure you will find them in many libraries)
We have a tool written in C# where we write vb.net scripts. Now, I need to integrate python in it so that we can run python scripts in same tool. All, the tool does is send string command and capture the string response.
My question: do I need to write interpreter for this?How can I talk to python engine. Is there any other way I can implement this? Links to get it going would be helpful. Just started with python today!
Thanks!
Look into IronPython to fill your scripting needs. IronPython will provide you all of the features of Python but from within the .Net framework. Here is a previous question concerning embedding IronPython in C#
Michael Foord has an post on embeddeding IronPython into C#. There are several methods to achieve this goal. The simplest being to create a hosting engine from within C# and embed a string of Python code that will be executed.
I am developing some visualization apps using an open-source framework called Omegalib:
https://code.google.com/p/omegalib/
This framework was originally written in C++ but has since incorporated Python versions of the C++ libraries. All of the pre-compiled python modules for Omegalib are provided as dynamic link libraries.
I would love to add some code-completion to my development environment as well as some stronger debugging capabilities than IDLE. In order to do this I need to provide the Python Omegalib libraries to whatever IDE I am using.
I've asked the developer if he knows how to achieve this and according to him, "...The reason is that omegalib python modules are not written in python, but in C++, and since I'm using an embedded interpreter there is no easy way (that I'm aware of, at least) to read the Python version of the modules".
So does anyone know how I can read in the .dll module files as Python code?
Thank you!
You can use ctypes to interface with a library if it has a c api.
However if it only has a C++ api, your only options are with a c extension module. Now there is cython to help with that which supports c and c++. It makes c extensions easier to write via python-like language.
Would it be possible to integrate Python (and/or Perl) and Ruby? I've looked at http://www.goto.info.waseda.ac.jp/~fukusima/ruby/python/doc/ and http://code.google.com/p/ruby-perl/ , but they both seem rather outdated.
Has someone generated a Ruby interface for Python's C API?
Edit: Python can be integrated with many other languages according to http://wiki.python.org/moin/IntegratingPythonWithOtherLanguages . However, that list doesn't include Ruby.
My school (Georgia Tech), along with Bryn Mawr and Microsoft Research, are doing a project right now called Pyjama. Basically, it uses the Microsoft DLR to allow you to freely mix Python and Ruby. I haven't tried it, but it sounds pretty cool.
Here's an example from the website. You enter the class in "Python mode". Then it gets compiled, and you run the command in "Ruby mode".
class PythonClass:
def hello(self, value):
print "Python says hello to", value
pc = python_class().new
pc.hello "Ruby"
Which produces "Python says hello to Ruby".
Integrating dynamic languages is one of the goals of the Parrot project. It's a virtual machine that dynamic language compilers target. Once compiled to the same virtual machine, you should be able to used the "object" form in any of the languages no matter the object's source.
The issue at the moment, however, is stabilizing the virtual machine and finishing off the mostly done compilers. However, that's been the state for a long time. :)
You can write extensions for Ruby in C.
So, if Python has a C API, you can write a C extension for Ruby which uses this API.
I know nothing about the Python API or how large of a piece you want to integrate with, but if it is not too big, this could (possibly) give you a way to run Python code from Ruby.
For a research project I wanted to use the fabulous matplotlib that's available for Python. I also found that library that you referred to. However, it doesn't look like something popular and well tested. So I decided to write the script that generated graphs using pure Python and called it from Ruby via popen. That worked very well for me.
It might by possible, but not very practical. It would be significantly easier to port whatever modules you need from one to the other than it would be to embed one of the interpreters within the other.
If you absolutely have to use both languages in a project, your best option would probably the combination of Jython and Jruby, or IronPython and IronRuby. I'm not sure if you could get them to talk to each other, but at the very least you could host them on the same virtual machine.
Another strategy, as used by Facebook, is to expose APIs via Thrift. You define lightweight service APIs and the RPCs are inter-process.
I have a third-party product, a terminal emulator, which provides a DLL that can be linked to a C program to basically automate the driving of this product (send keystrokes, detect what's on the screen and so forth).
I want to drive it from a scripting language (I'm comfortable with Python and slightly less so with Perl) so that we don't have to compile and send out executables to our customers whenever there's a problem found.
We also want the customers to be able to write their own scripts using ours as baselines and they won't entertain the idea of writing and compiling C code.
What's a good way of getting Python/Perl to interface to a Windows DLL. My first thought was to write a server program and have a Python script communicate with it via TCP but there's got to be an easier solution.
One way to call C libraries from Python is to use ctypes:
>>> from ctypes import *
>>> windll.user32.MessageBoxA(None, "Hello world", "ctypes", 0);
In Perl, Win32::API is an easy way to some interfacing to DLLs. There is also Inline::C, if you have access to a compiler and the windows headers.
Perl XSUBs can also create an interface between Perl and C.
In Perl, P5NCI will also do that, at least in some cases. But it seems to me that anything you use that directly manages interfacing with the dll is going to be user-unfriendly, and if you are going to have a user (scriptor?) friendly wrapper, it might as well be an XS module.
I guess I don't see a meaningful distinction between "compile and send out executables" and "compile and send out scripts".
For Python, you could compile an extension which links to the DLL, so that in Python you could just import it like a normal module. You could do this by hand, by using a library like Boost.Python, or by using a tool such as SWIG (which also supports Perl and other scripting languages) to generate a wrapper automatically.
The Python Py_InitModule API function allows you to create a module from c/c++ functions which can then be call from Python.
It takes about a dozen or so lines of c/c++ code to achieve but it is pretty easy code to write:
https://python.readthedocs.org/en/v2.7.2/extending/extending.html#the-module-s-method-table-and-initialization-function
The Zeus editor that I wrote, uses this appoach to allow Zeus macros to be written in Python and it works very well.