How do you use Python with C and Java simultaneously? [closed] - python

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Edit<<<<<<<
The question is:
-How do you launch C code from python? (say, in a function)
-How do you load Java code into python? (perhaps in a class?)
-Can you simply work with these two in a python program or are there special considerations?
-Will it be worth it, or will integrating cause too much lag?
Being familiar with all three languages (C, Java and Python) and knowing that Python supports C libraries, (and apparently can integrate with Java also) I was wondering if Python could integrate a program using both languages?
What I would like is fast flexible C functions while taking advantage of Java's extensive front-end libraries and coordinating the two in Python's clean, readable syntax.
Is this possible?
EDIT---->
To be more specific, I would like to write and execute python code that integrates my own fast C functions. Then, call Java libraries like swing to create user interface and handle networking. Probably taking advantage of XML as well to aid in file manipulation.

To be more specific, I would like to write and execute python code that integrates my own fast C functions. Then, call Java libraries like swing to create user interface and handle networking. Probably taking advantage of XML as well to aid in file manipulation.
Integrating C code into Python is quite easy using modules such as ctypes or cffi.
Integrating Java code into Python is not simple, and is likely well beyond your ability. There are plenty of very capable user interface, networking, and XML processing libraries available for Python; you don't need Java to do any of that.

For C, you can use ctype module or SWIG.
For Java, Jython is a good choice.

Related

Why are so many Python libraries written in C/C++ [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
In most languages, it's safe to assume libraries are written in the same language, ie. a Java library is usually written in Java.
In Python, that doesn't seem to be the case. Many of the high performance libraries such as numpy, pandas and more are written in C/C++, and provide Python bindings for convenience. It seems we could call these C/C++ libraries instead of Python libraries.
Why is this?
Your question had the answer buried in it: "Many of the high performance libraries...are written in C/C++."
There are two reasons for calling a low-level language from a language like Python, and performance is one of them. Numpy, for example, achieves a lot of its performance by carefully managing (and reusing) memory, and calling it from Python avoids the garbage collection overheads of writing the same functions in Python.
The other reason to call libraries written in another language is to do things not possible in the source language, such as taking advantage of non-blocking I/O system calls, or using special features of a platform such as vector processing instructions, or GPGPUs.

Is python a good choice to build a desktop application? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 7 years ago.
Improve this question
I'm wondering if python is a good choice to develop a desktop application for a small business.
Is it possible to build something using PyQT or even Swing + Jython ? How I can make a executable file at the end?
I've found Python to be an excellent choice for developing a broad scala of applications including desktop applications. I've developed in C++ for many years, and for parts that are really time critical I sometimes use it still, but for most of my code Python helps me get results much faster. There are several ways to get an executable. Py2exe is one of them, Cython another option allowing easy combination with C++ if you need raw speed, interfacing with 3rd party libaries or low level control of devices. It also makes reverse engineering a bit harder, if that's a concern in your project.
By the way, when I started out with Python I was very concerned about performance and (being a quality manager at that time) almost blocked its introducion in our company for its lack of strickt typing. I was wrong about both. Since especially the rich set of built in datastructures as well as many of its standard modules are written in C++ and have been carefully optimized, it isn't so easy to beat on speed and memory efficiency as one might think. And the dynamic typing (only recently introduced in a language like C#) proved a very powerful means to write concise, readable, reliable and compact code.
I don't have shares (since Python is open source anyhow) but from all the languages I've used in the past (Algol, Pascal, Modula II, Assembler, Basic, Fortran, Cobol, C, C++, C#, Java, JavaScript) it's the one I prefer rightnow to earn a living with.
It depends on what you are looking to do. I have done it and it worked but there are other questions that can factor in like who will maintain or update the code, and do they know Python. You can look at cx_freeze for making a windows executable out of a python program as one of many options.

Is there a Python reusable component that is like the Blender node editor? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking us to recommend or find a tool, library or favorite off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
Closed 8 years ago.
Improve this question
Blender has a powerful, fun-to-use, flexible node editor:
Is there a Python library that will allow me to easily create a visual developing environment like this? In Blender, the node editor works with shaders, images, colors and the like, and I'd like to define the types of nodes, sockets and preview widgets myself, as in building a "visual DSL".
Edit: I don't want to create custom nodes within Blender, but use a component LIKE the node editor in my own projects. I removed the Blender tag to avoid confusion.
You can find how to do that in the documentation:
http://wiki.blender.org/index.php/User:Phonybone/Python_Nodes
If you want to use the nodes to build objects and meshes procedurally with it then I recommend you to use and/or fork and and improve this project:
http://wiki.blender.org/index.php/Extensions:2.6/Py/Scripts/Nodes/Sverchok
(These guys are also using the API linked above)
If you have blender specific questions, like this, I also recommend you to ask it on this blender dedicated stack exchange site:
https://blender.stackexchange.com/
EDIT:
As far as I know, there isn't any pre-made node-editor widget or anything similar like that in any UI libraries. However it is quite easy to implement the basic rectangles , input and output ports and the bezier lines to connect them. After the first steps it is only a matter of preference how many hours you put into design and smaller details.
I implemented my own in Python with the builtin tkinter library:
And then later in Pyglet and after that to improve speed I implemented it in pure C with OpenGL wrapped with Cython for Python usage:

why do people say that RPython is an unpleasant language to program in [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
It is often stated that RPython is an unpleasant language to program in, for example, here, here, here or here.
However, for example here in the original paper about RPython, it says quite the opposite:
The result is a language that is more expressive than C# and Java, but
which does not compromise runtime efficiency. RPython was initially
designed for the specific purpose of implementing PyPy [25] (a Python
interpreter written in Python), but it has grown into a full-fledged
language in its own right.
Currently, RPython can be used in many contexts: to develop
stand-alone programs, such as the Standard Interpreter itself; to
write highly efficient extension modules for CPython, which could only
be written in C in the past; to develop dynamic web applications
without the need to write JavaScript code; to produce efficient
libraries of classes and functions to be used by other .NET and Java
programs. In particular, RPython can be the ideal companion for all
those CPython, IronPython and Jython developers that so far have been
forced to write the parts of their programs that need high performance
in C, C# or Java.
A related question for using RPython as a general purpose language is also here. I was also wondering about using RPython as a replacement for Cython. A related question is here. There is also the RPythonic project.
Why is it that people recommend against using RPython?
from here:https://mail.python.org/pipermail/pypy-dev/2013-June/011503.html
"
When people look at RPython, an obvious feature is that it is
syntactically identical to Python. "RPython must be an easy language,
given that it has got the syntax of Python, which is easy". This is a
common misconception. In fact, pleasing the automatic type inference
process can be difficult. It requires the programmer keeping in his
head the global types of his whole program, and carefully writing code
according to these implicit types. The process is much harder for
newcomers, which don't have any written-down example to learn how to
manipulate the types --- precisely because they are implicit.
"
I have made one file conversion program using RPython toolchain. Simple buffered file input and output. I can't imagine with my skills easier language to make such a fast, reliable, low bugs program.
What works and what doesn't is not well documented but once you find things out it is really nice set of tools to make small, fast and reliable programs.

Reference manual for python? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 5 years ago.
Improve this question
Is there a recommended reference manual for python that's better than the official docs? I'm an experienced programmer (PHP, C#, javascript, and some C most recently), and I find the python manual pretty lacking compared the PHP manual and MSDN. In particular, the official docs never seem to tell me what errors can happen if I pass in something invalid, and there's apparently not a way to navigate within a module.
Take the os module for example. There's no list of constants or methods I can call on that page, so I have to Ctrl+f for "stat(" until I find it. Then, once I do find it, it doesn't tell me what to expect if I call stat with a directory that doesn't exist, so I just have to try it in a terminal and see what happens.
This seems wildly inefficient… how do python programmers deal with this?
In practice, you either make a quick test program to check the behavior, or read the source code. Much of the Python standard library code is fairly clearly written and in fact rather self-documenting, so it's standard practice to refer to it when you need to know the nitty-gritty details of how something works.
One exception: with low-level system functions such as many of those in the os module, the functions map directly on to their C namesakes for the underlying platform. So if you need to know about the behavior of Python's stat, you look up the reference documentation for your platform's native C stat call. In these cases the Python library docs often only explain the basic purpose of the function and how it differs from its C equivalent, if at all.
I don't think I ever had the same feeling towards the python docs as you do but I did some times need to go out of my way some times for a better understand of how a part of python works. Though that is how most language are. Python is a quick and easy language to learn which requires less time on docs and more time programming. Also python's user base isn't as large as PHP. PHP has people constantly giving examples and details on certain functions daily.
Another great thing about python is its interactive shell to test things out. Just my idea of programming you learn more by doing then seeing. So if you're ever interested in testing something you don't need to drag through compiling, just write a quick script in the interpreter. the interpreter also has reference tools. Example dir(<identifier>) and help(<identifier>) for module, clasa or function needs.
Any way enough defending my favorite language, pyDoc is a little useful tool to help you get what you need from python.
pydoc is a tool that comes with Python that can be used for viewing
and generating Python documentation.

Categories