12
votes
6answers
13k views

Python function pointer

I have a function name stored in a variable like this: myvar = 'mypackage.mymodule.myfunction' and I now want to call myfunction like this myvar(parameter1, parameter2) What's the easiest way to ...
8
votes
3answers
128 views

In python, when you pass internally defined functions into other functions, how does it keep the variables?

For example, why does this work? def func1(func1var): def innerfunc(innerfuncvar): if func1var == 1: print innerfuncvar else: print 5 ...
5
votes
2answers
2k views

EventHandler, event, delegate based programming in Python any example would appreciate?

Basically I'm a C# developer, I know the way C# does, EventHandler, delegate, even... but whats the best way to implement it on Python.
5
votes
1answer
214 views

Do function pointers remain valid across processes?

I have written an extension module that uses C++ function pointers to store sequences of function calls. I want to 'run' these call sequences in separate processes using python's multiprocessing ...
4
votes
2answers
401 views

Python, how to pass an argument to a function pointer parameter?

I only just started learning Python and found out that I can pass a function as the parameter of another function. Now if I call foo(bar()) it will not pass as a function pointer but the return value ...
4
votes
3answers
310 views

Python ctypes: How to modify an existing char* array

I'm working on a Python application that makes use of libupnp which is a C library. I'm using CTypes to use the library which is easy enough. The problem I'm having is when I'm registering a callback ...
3
votes
3answers
2k views

anonymous unbound functions in python

I would like to do something like the following: def add(a, b): #some code def subtract(a, b): #some code operations = [add, subtract] operations[0]( 5,3) operations[1](5,3) In python, is ...
3
votes
3answers
71 views

Pointers to static methods in Python

Why is it that in the following code, using a class variable as a method pointer results in unbound method error, while using an ordinary variable works fine: class Cmd: cmd = None ...
2
votes
5answers
297 views

Python: some newbie questions on sys.stderr and using function as argument

I'm just starting on Python and maybe I'm worrying too much too soon, but anyways... log = "/tmp/trefnoc.log" def logThis (text, display=""): msg = str(now.strftime("%Y-%m-%d %H:%M")) + " ...
1
vote
3answers
127 views

Why do function objects evaluate to True in python?

In python it is valid to make a construction like: def a(): return 0 if a: print "Function object was considered True" else: print "Function object was considered False" I wish to ...
1
vote
3answers
659 views

Python: how to create a function pointer with a set argument?

My problem: Given the following: def foo(a,b) I am trying to call the python 'map' function while passing in a list for 'a' but use a set value for 'b.' Another relevant fact is that 'b' is user ...
1
vote
3answers
657 views

How to pass tuple as parameters of a function

I have a tuple containing tuples. EVENT_MAPPING = ( (func1, (paramA1, paramA2, paramA3)), (func2, (paramB1)), (func3, (paramC1, paramC2)), ) I iterate over the first tuple. And I want ...
1
vote
2answers
2k views

Python ctypes and function pointers

This is related to my other question, but I felt like I should ask it in a new question. Basically FLAC uses function pointers for callbacks, and to implement callbacks with ctypes, you use CFUNCTYPE ...
1
vote
2answers
98 views

C++ regex library with substitution to function pointer [closed]

Looking for something similar to Python's regex sub or subn methods. http://docs.python.org/library/re.html So basically a C/C++ api like this re.sub(pattern, repl, string, count=0, flags=0) ...
1
vote
1answer
316 views

Embedding Python and adding C functions to the interpreter

I'm currently writing an applications that embedds the python interpreter. The idea is to have the program call user specified scripts on certain events in the program. I managed this part but now I ...

1 2
15 30 50 per page