Steven D'Aprano wrote: > On Fri, 19 Oct 2007 16:19:32 +0200, stef wrote: > > >> Well I'm not collecting data, I'm collecting pointers to data. >> > > I beg to differ, you're collecting data. How that data is to be > interpreted (a string, a number, a pointer...) is a separate issue. > > > >> This >> program simulates a user written program in JAL. As Python doesn't >> support pointers, instead I collect names. >> > > This doesn't make any sense to me. If your user-written program is > supplying pointers (that is, memory addresses like 0x15A8), how do you > get a name from the memory address? > > > If you are trying to emulate pointer-manipulation, then the usual way to > simulate a pointer is with an integer offset into an array: > > # initialise your memory space to all zeroes: > memory = [chr(0)]*1024*64 # 64K of memory space, enough for anyone > NULL = 0 > pointer = 45 > memory[pointer:pointer + 5] = 'HELLO' > pointer += 6 > memory[pointer:pointer + 5] = 'WORLD' > > > If there is a better way, I'ld like to hear it. I understand that execute is dangerous.
I don't have pointers, I've just names (at least I think). Let me explain a little bit more, I want to simulate / debug a user program, the user program might look like this: x = 5 for i in xrange(10): x = x + 1 So now I want to follow the changes in "x" and "i", therefor in the background I change the user program a little bit, like this def user_program(): x = 5 ; _debug(2) global x,i _debug (3) for i in xrange(10): _debug (3) x = x + 1 ; _debug (4) And this modified user program is now called by the main program. Now in the _debug procedure I can set breakpoints and watch x and i. But as in this case both a and i are simple integers, I can not reference them and I need to get their values through their names, and thus a execute statement. I couldn't come up with a better solution ;-) (There may be no restrictions laid upon the user program, and indeed name clashing is an accepted risk). cheers, Stef -- http://mail.python.org/mailman/listinfo/python-list