Do you know of any Python module for resources (resx files) manipulation?
P.S.: I know I could write a custom wrapper on top of base XML processor available, I'm just checking out before going to hack my own code...
This question Resources (resx) maintenance in big projects has an answer pointing to some .NET source code for a tool to manage RESX resources. Since IronPython can interface with any existing .NET objects written in C#, you should be able to adapt that RESX tool source code into an object that you can then use in IronPython.
Related
I need to access data via USB from a beam profiler. I've tried using the USB module in python to access it, but unfortunately the company who makes this device "does not support development in Python". The project I am working on is to eventually create a GUI (via Python) to automate a motor and pull data from the device. So it has to be done in Python, or I'm going to have to discard the first half of the code and redo it in C++.
I think the reason the device can only interface with C/C++ is because of the header and library files that come with the driver download.
I've looked at Cython but am still very unsure how it can help me. I'm just trying to access the header files for the driver in python and somehow execute the C commands in python.
BTW I am using Anaconda (if that matters).
Thank-you for any clarification and help!
Check out boost.python
Here is an intro:
The Boost Python Library is a framework for interfacing Python and
C++. It allows you to quickly and seamlessly expose C++ classes
functions and objects to Python, and vice-versa, using no special
tools -- just your C++ compiler. It is designed to wrap C++ interfaces
non-intrusively, so that you should not have to change the C++ code at
all in order to wrap it, making Boost.Python ideal for exposing
3rd-party libraries to Python. The library's use of advanced
metaprogramming techniques simplifies its syntax for users, so that
wrapping code takes on the look of a kind of declarative interface
definition language (IDL).
It includes support for:
References and Pointers
Globally Registered Type Coercions
Automatic Cross-Module Type Conversions
Efficient Function Overloading
C++ to Python Exception Translation
Default Arguments
Keyword Arguments
Manipulating Python objects in C++
Exporting C++ Iterators as Python Iterators
Documentation Strings
and many more.
I did a dumb thing. I got all excited about Revit 2014 allowing macros in Ruby, installed RevitRubyShell, and wrote what is going to become an add-in.
Slight problem -- there's no DLL compiler for IronRuby. D'oh!
So, I'm going to convert my code to Python (and use the excellent RevitPythonShell), which is what I was using for Revit API work before Revit 2014 Ruby came along.
My question is -- after I've converted my Ruby code to Python, (how) can I create a Revit Add-In DLL? I know that you can compile Python to a .NET DLL, but every example of Revit Add-Ins seems to be in C#. I want to stay in the interpreted environment because it's very fast to develop in Revit this way. But there's no point in doing all my dev in Python (or Ruby) if I have to convert everything to C# to make an Add-in that conforms to the IExternalApplication interface.
Has anyone done a Revit Add-In in Python?
Thanks!
Andy
Check out this blog post: Deploying RPS scripts with DeployRpsAddin.
In that article, I describe a functionality of the RevitPythonShell, that let's you create a distributable version of your RevitPythonShell (RPS) scripts - a bunch of scripts to ship.
The main way this is done is by providing a wrapper DLL written in C# that stores your scripts and a configuration file as resources and executes them with IronPython at runtime. This still means that your python code is not "compiled" to IL, but you get to bundle it up for installation on a separate computer. Check out the DesignPerformanceViewer for an elaborate example of such an AddIn.
Never mind. After more digging, found this stackoverflow answer that indicates IronPython DLLs are NOT portable/callable from anything but IronPython, so that leaves out Revit Add-ins.
Build .NET DLLs from Python code? (the answer, per this link, is "No.")
During developing one of my applications, I've come to a point where I'd like to give the users a more powerful filter. Therefore, I'd like to provide a simple scripting interface to the users. The scripting language would be Python.
For obvious reasons, I'd like to tighten the scope of the language to match my particular purposes (I don't want the users to touch the server's HDD files etc.). I also don't want to write a Python interpreter myself (which would be reinventing the wheel and the "new" wheel would be rectangular in the end). However, I haven't found any suitable library or module for this purpose.
Groovy's approach with its Compilation Customizers and Compiler Configuration would be exactly what I want, does something similar exist for Python?
What you're looking for is called a "sandbox" or "restricted execution." This wiki page discusses some of the details.
In a nutshell, there have been several efforts by Python geeks and gurus to build a sandbox on top of Python but they all failed eventually.
The main reason is that Python offers so many paths to do something that the sandbox would either have to forbid common use cases (rendering a lot of the library and Python code useless) or it would have to have holes in the sandbox which would make the concept useless.
So while it looks like a good and simple idea, so far, there is no solution. AFAIK, there are no hooks in Python to tweak the byte code compiler to achieve something like Groovy Sandbox.
Related:
How can I sandbox Python in pure Python?
Is there a "safe" subset of Python for use as an embedded scripting language?
I used cpython api to load py from C/C++.
But, if i want not setup cpython in client, can I take package dll of cpython in my program?
How to do that?
Installer-builders like PyInstaller (cross-platform) and py2exe (Windows only) basically do that job for you in a general way, except that the executable at the heart of the produced package is their own instead of yours.
But basically, you can imitate their behavior in terms of setting up a .zip file with all the Python library modules you need (or just zip up everything in the standard python library if you want to allow python code running form your app to import anything from there), and follow the simple advice in the Embedding Python in Another Application section of the Python docs.
Note that embedding Python equals extending Python plus a little bit of code to initialize and finalize the interpreter itself and a little bit of packaging as I just mentioned; if you've never writted Python extensions I would suggest practicing that first since it's the most substantial part of the task (not all that hard with helpers such as boost python, but more work if you choose to do it as the "bare C" level instead).
You don't need to setup Python to embed it in applications. The core of the Python interpreter is available as a shared library which you can dynamically load in your application and distribute with it.
Read on embedding Python in the official docs. Also, this article seems nice and comprehensive for Linux. For Windows, read the notes here.
Here's another SO question that discusses this issue.
The Python license is probably hard to understand for a non-lawyer, non-native English speaker. So yes, you can redistribute the unmodified DLL as it contains the copyright notice within it.
It would be polite to give credit like "This program contains the Python Language Interpreter version X.XX http://python.org for more information" or similar somewhere in the program or documentation.
I recently started learning Python. Not yet ventured into coding.
During one of my learning sessions, i came accross the term Jython.
I googled it & got some information.
I would like to know if anyone has implemented any real-world program using Jython.
Most of the time, Jython isn't used directly to write full read-world programs, but a lot of programs actually embed Jython to use it as a scripting language.
The official Jython website gives a list of projects, some written in Jython, others using Jython for scripting:
http://wiki.python.org/jython/JythonUsers
I am writing a full application in Jython at the moment, and would highly recommend it. Having all of the Java libraries at your disposal is very handy, and the Python syntax and language features actually make using some of them easier than it is in Java (I'm mostly talking about Swing here).
Check out the chapter on GUI Applications from the Jython book. It does a lot of comparisons like 'Look at all this Java code, and now look at it reduced to Python code of half the length!'.
The only caveats I've found are:
Jython development tends to run slightly behind Python, which can be annoying if you find a cool way of doing something in Python, only to discover it's not supported in the current Jython version.
Occasionally you might have hiccups with the interface between Python and Java (I have a couple of unsolved problems here and here, although there are always workarounds for this kind of thing).
Distribution is not as simple as it could be, although once you figure out how to do it, it's fairly painless. I recommend following the method here. It essentially consists of:
Exploding jython.jar and adding your own modules into it.
Writing and compiling a small Java class that creates a Python interpreter and loads up your Python modules.
Creating an executable .jar file consisting of the jython.jar modules, your own Python modules, and the Java class.
Jython really shines for dependency injection.
You know those pesky variables you have to give your program, like
file system paths
server names
ports
Jython provides a really nice way of injecting those variables by putting them in a script. It works equally well for injecting java dependencies, as well.
WebSphere and WebLogic use it as their default scripting engine for administrative purposes.
A lot of other Oracle products ship it as part of their "oracle_commons" module (Oracle Universal Installer, Oracle HTTP Server etc). It's mostly version 2.2 being deployed though, which is a bit old and clunky.
There is a list of application that uses jython at http://wiki.python.org/jython/JythonUsers