ctypes - random access to address space
Hi, I am currently doing a project in which I interface to a PCI card. To ease the prototyping, I call the API functions, which map the address space of the card to a process memory. I acquire the location in the process memory mapped to an address space using card API, resulting in a c structure, containing an integer field, being a location. The question is, if I can create a ctypes pointer to this location. Is that what i.e. POINTER(uint32).from_address() does? Jan Wicijowski -- http://mail.python.org/mailman/listinfo/python-list
Re: If your were going to program a game...
On 1 Sty, 12:37, Tokyo Dan huff...@tokyo.email.ne.jp wrote: If your were going to program a game in python what technologies would you use? The game is a board game with some piece animations, but no movement animation...think of a chess king exploding. The game runs in a browser in a window of a social site built around the game. The social site has login, chat, player stats, list of active games, etc. AND there is also be a desktop client that accesses the game server via the same communication mechanism (like an AIR-based desktop client/ app) as the browser-based version - I guess using JSON/RPC. If I were to write a python game that ran in a _browser_ I'd go for jython applet. JW -- http://mail.python.org/mailman/listinfo/python-list
Re: multiprocessing vs thread performance
On 29 Gru, 15:52, mk mrk...@gmail.com wrote: Hello everyone, After readinghttp://www.python.org/dev/peps/pep-0371/I was under impression that performance of multiprocessing package is similar to that of thread / threading. However, to familiarize myself with both packages I wrote my own test of spawning and returning 100,000 empty threads or processes (while maintaining at most 100 processes / threads active at any one time), respectively. The results I got are very different from the benchmark quoted in PEP 371. On twin Xeon machine the threaded version executed in 5.54 secs, while multiprocessing version took over 222 secs to complete! Am I doing smth wrong in code below? Or do I have to use multiprocessing.Pool to get any decent results? Oooh, 10 processes! You're fortunate that your OS handled them in finite time. [quick browsing through the code] Ah, so there are 100 processes at time. 200secs still don't sound strange. JW -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter 3.0 multiple keyboard events together
On 28 Gru, 09:43, Pavel Kosina g...@post.cz wrote: well, I am working on a tutorial for youngster (thats why i need to stay the code as easy as possible). In this game you are hunted by robots. I could use key7 on numeric keypad for left-up moving but seems to me, that 4+8 is much more standard for them. Hmmm. Maybe you'd like to hook into Tkinter event loop, i.e. by custom events if you don't like periodical polling. No, that would be even more difficult. I already have a code that use your idea: from Tkinter import * root = Tk() pressedKeys=set() def onKeyPress(event): pressedKeys.add(event.keysym) def onKeyRelease(event): pressedKeys.remove(event.keysym) def move(): print list(pressedKeys) root.after(100,move) root.bind(KeyPress, onKeyPress) root.bind(KeyRelease, onKeyRelease) root.after(100,move) root.mainloop() well, I thought that gui´s have such a problem already built-in - so that i am not pressed to code it. You know, its not exactly about me - if I do it for myself, for my program, that there is no problem, but I need to explained it to begginners . And I do not want, as might be more usual, do my module, that would cover this insanity (look at it with 13-years old boy eyes ;-) ). Do you like to say me, that this is not a standard function neither in tkinter, not say gtk or the others, too? Ok, I get it then! Your goal is very humble :) In the piece of code we have came together to, there is a functionality you already want - the pressedKeys. I suppose, that you'd like to hide from the further implementors (children). You can write another module, which could contain this piece of code and could be imported by kids to have the desired features. Meaning only getting this list of keys. But what you write here: I would expect something like this: def onKeyTouch(event): print (event.keysymAll) root.bind(KeyPress, onKeyTouch) ...is a bit misleading. There is no such thing as simultaneous events - for that the event dispatcher loop is designed - to simplyfy all usual stuff with parallel paradigsm such as interrupts, thread safety etc. An event is in my eyes a response to a short action, let's call it atomic. There's no need to pretend, that clicking a few keys simultanously is sth immediate and the software could by any chance guess that a few keys were actually clicked. Even the keyboard driver does some sequential scanning on the keys, and the key codes are then send to the board sequentially as well. Try to run this code: # #Tkinter multiple keypress #Answer http://groups.google.com/group/comp.lang.python/browse_thread/thread/88788c3b0b0d51d1/c4b7efe2d71bda93 import Tkinter import pprint import time tk = Tkinter.Tk() f = Tkinter.Frame(tk, width=100, height=100) msg = Tkinter.StringVar() msg.set('Hello') l = Tkinter.Label(f, textvariable=msg) l.pack() f.pack() keys = set() lastTime = None def keyPressHandler(event): keys.add(event.char) global lastTime now = time.time() if lastTime: difference = now - lastTime if difference 0.1: #seconds print difference, 's' lastTime = now display() def keyReleaseHandler(event): keys.remove(event.char) display() def display(): msg.set(str(keys)) f.bind_all('KeyPress', keyPressHandler) f.bind_all('KeyRelease', keyReleaseHandler) f.mainloop() # ... and find out, how 'simultaneous' they are. For me it's 0.0, meaning that the event handlers were executed one after another, but sometimes there is sth like 0.0309998989105 s - proabably an USB latency, or an operating system context switch - hard to tell. If you'd like to have two key clicks to generate a single event, you'd have to write some timeout code (threading.Timer or tk stuff is handy) to check how 'simultaneous' they actually were. Search web for events in doubled inequality signs if you really want this. I don't know gtk, but hey, pygame has pygame.key.get_pressed if you'd like to switch: http://www.pygame.org/docs/ref/key.html Have luck Jan -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter 3.0 multiple keyboard events together
On 26 Gru, 17:44, Pavel Kosina g...@post.cz wrote: janislaw napsal(a): On 26 Gru, 05:52, Pavel Kosina g...@post.cz wrote: Is it possible to catch in an event more that one key from keyboard? In my code, I can handle always the only one, the first I press, the others are omitted. Say, I press both 4 and 8 and only 4 is catched. def movePlayer(event): print (event.keysym) Each keypress triggers another event. Fortunately there are two types of events: reaction to press and release. The logic to write to recognize those as simultaneous clicks is up to you :) Might you give me a little bit more? Just a link to a site where this is explained and showed would be OK. I really did my best but everything is bad. geon Use google to find the appropriate site, or browse this site, there are plenty of examples. You may want to examine the code I wrote to you to catch the idea: #-- import Tkinter import pprint tk = Tkinter.Tk() f = Tkinter.Frame(tk, width=100, height=100) msg = Tkinter.StringVar() msg.set('Hello') l = Tkinter.Label(f, textvariable=msg) l.pack() f.pack() keys = set() def keyPressHandler(event): keys.add(event.char) display() def keyReleaseHandler(event): keys.remove(event.char) display() def display(): msg.set(str(keys)) f.bind_all('KeyPress', keyPressHandler) f.bind_all('KeyRelease', keyReleaseHandler) f.mainloop() # Regards, JW -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter 3.0 multiple keyboard events together
On 27 Gru, 15:08, Pavel Kosina g...@post.cz wrote: janislaw napsal(a): Use google to find the appropriate site, or browse this site, there are plenty of examples. You may want to examine the code I wrote to you to catch the idea: #-- import Tkinter import pprint tk = Tkinter.Tk() f = Tkinter.Frame(tk, width=100, height=100) msg = Tkinter.StringVar() msg.set('Hello') l = Tkinter.Label(f, textvariable=msg) l.pack() f.pack() keys = set() def keyPressHandler(event): keys.add(event.char) display() def keyReleaseHandler(event): keys.remove(event.char) display() def display(): msg.set(str(keys)) f.bind_all('KeyPress', keyPressHandler) f.bind_all('KeyRelease', keyReleaseHandler) f.mainloop() Is this really the most simple solution how to do this in Tkinter? Is there nothing cleaner build inside? Um, I could be only guessing what are you meant to do, unless you describe your problem in more detailed way. I.e. describe the desired behaviour, show code which you have, and describe the current behaviour. This solution has disadvantage that after you release one key, that the function keyPressHandler stopped to be called by the other pressed keys. I would have not to build moving the player in KeyPresshandler, but on another new function that would have to read periodically keys and to act afterwards Hmmm. Maybe you'd like to hook into Tkinter event loop, i.e. by custom events if you don't like periodical polling. From what I am guessing, you expect that 2 keyboard events are simultaneous and can be cached at the same time instant. Well that would be impossible, cause all the underlying hardware is sequential. You may have parallel stuff if you go down to VHDL and write your own hardware, but when you have a CPU, then you'll have to stick with writing programs. C'mon, 20 lines is not such a big deal. Regards JW -- http://mail.python.org/mailman/listinfo/python-list
Re: tkinter 3.0 multiple keyboard events together
On 26 Gru, 05:52, Pavel Kosina g...@post.cz wrote: Is it possible to catch in an event more that one key from keyboard? In my code, I can handle always the only one, the first I press, the others are omitted. Say, I press both 4 and 8 and only 4 is catched. def movePlayer(event): print (event.keysym) Thank you. -- geon Pavel Kosina Each keypress triggers another event. Fortunately there are two types of events: reaction to press and release. The logic to write to recognize those as simultaneous clicks is up to you :) JW -- http://mail.python.org/mailman/listinfo/python-list
Re: Interrupt python thread
On 24 Sie, 10:48, BlueBird [EMAIL PROTECTED] wrote: Whenever an exception occurs, in the master thread or in one of the slave threads, I would like to interrupt all the threads and the main program. Threading API does not seem to provide a way to stop a thread, is there anyway to achieve that ? Note that killing, stopping, suspending and resuming Your thread at arbitrary time leads to unpredictable results. For this reason i.e. Java deprecated all such functions, and python didn't introduce them at all. It makes sense as it leads to better-designed-code. Regards JW -- http://mail.python.org/mailman/listinfo/python-list
Re: python custom command interpreter?
On 21 Sie, 07:45, Martin [EMAIL PROTECTED] wrote: I guess you are looking for this: http://docs.python.org/lib/module-cmd.html OP may also would like to hack his own language using EasyExtend: http://www.fiber-space.de/EasyExtend/doc/EE.html Most likely an overkill. -- Jan Wicijowski -- http://mail.python.org/mailman/listinfo/python-list
Re: Ideas for master's thesis
On Jun 3, 2:27 am, [EMAIL PROTECTED] wrote: I'm sure you could probably find something having to do with Pypy (http://codespeak.net/pypy/dist/pypy/doc/home.html) that would be both manageable and significant enough to warrant a Master's thesis. The Pypy will fade out. You can for example write a compiler for LISP to CPython bytecode. Fits well for a master thesis. Regards, Jan Wicijowski -- http://mail.python.org/mailman/listinfo/python-list
Re: How do *you* use Python in non-GUI work?
On May 19, 12:20 am, John Salerno [EMAIL PROTECTED] wrote: Hey all. Just thought I'd ask a general question for my own interest. Every time I think of something I might do in Python, it usually involves creating a GUI interface, so I was wondering what kind of work you all do with Python that does *not* involve any GUI work. This could be any little scripts you write for your own benefit, or what you do at work, if you feel like talking about that! :) Thanks. - Programs creating C and VHDL source files - Scipy scripts generating charts Jan Wicijowski -- http://mail.python.org/mailman/listinfo/python-list
Re: Increment Variable Name
On Jan 23, 11:45 pm, David Brochu [EMAIL PROTECTED] wrote: This is probably really trivial but I'm stumped :-( Does anyone know how to increment a variable name? For example: I know the length of a list and I want to pass each element of a list to a unique variable, thus I want to increment variable names. If the list length = 4, i want to have the following variables: var1, var2, var3, var4. Thanks Do you want to do this?: locals() {'__builtins__': module '__builtin__' (built-in), '__name__': '__main__', 'pywin': module 'pywin' from 'C:\Python25\Lib\site- packages\pythonwin\pywin\__init__.pyc', '__doc__': None} locals()['var'+str(1)] = spam locals() {'__builtins__': module '__builtin__' (built-in), '__name__': '__main__', 'var1': 'spam', 'pywin': module 'pywin' from 'C: \Python25\Lib\site-packages\pythonwin\pywin\__init__.pyc', '__doc__': None} var1 'spam' -- http://mail.python.org/mailman/listinfo/python-list
Re: Beginning Python
On Jun 5, 4:29 pm, abhiee [EMAIL PROTECTED] wrote: Hello , I have just begun learning python...and I'm loving it...Just wanted to ask you that how much time would it take me to learn python completely and which languages should i learn alongwith python to be a good professional programmer?...Now i only know C thanx in advance! Then Lisp is a must-know to you. -- http://mail.python.org/mailman/listinfo/python-list
Re: removing common elemets in a list
On May 16, 8:17 am, [EMAIL PROTECTED] wrote: Hi, Suppose i have a list v which collects some numbers,how do i remove the common elements from it ,without using the set() opeartor. Thanks There was a similar thread on polish python newsletter. The following post displays 4 different approaches and explores timings: http://groups.google.com/group/pl.comp.lang.python/msg/dc3618b18e63f3c9 Fortunately, python code is universal. -- http://mail.python.org/mailman/listinfo/python-list