I am trying to implement something similar to the Python with statement in C++. As I plan to use it mainly with Qt-OpenGL the methods are called bind and release (in Python __enter__, __exit__). Code I came up with: header: cpp: Usage: Questions: Needing class A and class B feels a bit clumsy. Is there a better alternative? Are there
Tag: c++
how to create empty c type array (or just one NULL value) in python?
I was wondering whether (and how) one can create empty c type arrays in python. The following code works fine if I want to initialize an array with zeros: If data is a list of None values however, I get an error message: is there a way to initialize and array with NONEs or NULLs? EDIT 1: the reason why
detecting bind mounts on linux
I am looking for a way to determine if a given path is a bind mount point (on linux). The standard techniques for detecting regular mount points don’t seem to work. Even the mountpoint command fails to detect bind mounts. Answer I’m not sure there is supposed to be a way to do that (except perhaps thru /etc/mtab or /etc/fstab)
How to calculate the angle between a line and the horizontal axis?
In a programming language (Python, C#, etc) I need to determine how to calculate the angle between a line and the horizontal axis? I think an image describes best what I want: Given (P1x,P1y) and (P2x,P2y) what is the best way to calculate this angle? The origin is in the topleft and only the positive quadrant is used. Answer First
PIL’s colour space conversion YCbCr -> RGB
The algorithm used by PIL v1.1.7 gives ‘washed out’ looking results. When converting the same source data using ffmpeg it looks correct. Using mplayer gives identical results to ffmpeg (perhaps they use the same library underneath). This leads me to believe PIL may be stuffing up the colour space conversions. The conversion seems to be sourced in libImaging/ConvertYCbCr.c: This is
Python interfacing with C library – How to have a null c pointer
I have the following old c code. Now, I need to use Python to call old c function. I have the following code. May I know what is the Python equivalent for c[2] = 0;? Answer None and 0 both work:
Implementing a function in Python vs C
Is there a difference (in terms of execution time) between implementing a function in Python and implementing it in C and then calling it from Python? If so, why? Answer Python (at least the “standard” CPython implementation) never actually compiles to native machine code; it compiles to bytecode which is then interpreted. So a C function which is in fact
Convert Python program to C/C++ code? [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 4 months ago. Improve this question is it possible to convert a Python program to C/C++? I need to implement a couple of algorithms, and I’m
How do I convert a Python list into a C array by using ctypes?
If I have the follow 2 sets of code, how do I glue them together? How can I call the c_function with a contiguous list of elements in x? I tried to cast x to a c_void_p, but that didn’t work. I also tried to use something like but this gets a syntax error. The C code clearly wants the
Finding invocations of a certain function in a c++ file using python
I need to find all occurrences of a function call in a C++ file using python, and extract the arguments for each call. I’m playing with the pygccxml package, and extracting the arguments given a string with the function call is extremely easy: What I couldn’t find is a way of getting the calls parsing a file: Is there a