Re: with timeout(...):

2007-03-26 Thread Nick Craig-Wood
James Stroud <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > Did anyone write a contextmanager implementing a timeout for > > python2.5? > > > > I'd love to be able to write something like > > > > with timeout(5.0) as exceeded

Re: with timeout(...):

2007-03-26 Thread Nick Craig-Wood
to kill one thread from another thread. There is a ctypes hack to do it, which sort of works... It needs some core support I think. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Nick Craig-Wood
Jean-Paul Calderone <[EMAIL PROTECTED]> wrote: > On Mon, 26 Mar 2007 16:50:33 +0200, Thomas Dybdahl Ahle <[EMAIL PROTECTED]> > wrote: > >Den Mon, 26 Mar 2007 06:30:04 -0500 skrev Nick Craig-Wood: > >> Under linux the only priviledge you need is CAP_NET_RAW. It i

Re: Sending ECHO_REQUEST (pinging) with python

2007-03-26 Thread Nick Craig-Wood
; command as ordinary user. > > The workaround your ping command is using btw, is probably running > suid root. Under linux the only priviledge you need is CAP_NET_RAW. It is possible to give this to a process - a bit of searching with google will show you how! -- Nick Craig-Wood <[EM

with timeout(...):

2007-03-26 Thread Nick Craig-Wood
ss platform way! >From my experiments with timeouts I suspect it won't be possible to implement it perfectly in python 2.5 - maybe we could add some extra core infrastructure to Python 3k to make it possible? -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/ni

Re: detect suprocess interaction

2007-03-26 Thread Nick Craig-Wood
password, eg... $ svn ls svn+ssh://[EMAIL PROTECTED]/svn /dev/null 2>&1 Password: I don't know exactly how it does that but I suspect it is to do with the controlling terminal... On my system $ setsid svn ls svn+ssh://[EMAIL PROTECTED]/svn /dev/null 2>&1 Pops up a gui box askin

Re: Garbage collection

2007-03-21 Thread Nick Craig-Wood
any fragmentation worries. However if you have lots of small allocations then the heap will be fragmented and you'll never be able to return the memory to the OS. However that is why we have virtual memory systems. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Using pxssh

2007-03-19 Thread Nick Craig-Wood
quot;ls -l") 6 >>> s.prompt() True >>> print s.before ls -l total 30944 -rw-r--r-- 1 user user 936 Nov 3 14:52 #z.c# [snip] -rw-r--r-- 1 user user 221 Jan 30 11:51 z~ >>> s.logout() >>> I'm using the debian packaged version 2.1-1 with python 2.4 -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Bitpacked Data

2007-03-12 Thread Nick Craig-Wood
ert data into dictionary You could try Construct http://construct.wikispaces.com/ This allows you to build a python class which will translate to and from that datastructure. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: number generator

2007-03-12 Thread Nick Craig-Wood
t goes round the while loop on average 0.5 times. If 0 isn't required then just test for it and go around the loop again if found. That of course skews the distribution in difficult to calculate ways! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http:/

Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Nick Craig-Wood
Robert Marshall <[EMAIL PROTECTED]> wrote: > On Fri, 09 Mar 2007, Bruno Desthuilliers wrote: > > > > > Nick Craig-Wood a ?crit : > >> [EMAIL PROTECTED] <[EMAIL PROTECTED]> wrote: > >>> What if 2 new 'special' comment-like character

Re: 2 new comment-like characters in Python to aid development?

2007-03-09 Thread Nick Craig-Wood
. ''' and ''' (if you normally use """ """ for docstrings) Python just ignores strings that lie around. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: pyHook or SetWindowsHookEx

2007-02-28 Thread craig wickesser
well the problem I have only occurs when my python app. is running as a Windows Service. if I run the python app. as a process (i.e. from the command line) it works as epxected via Remote Desktop. still not sure what's going on. On 2/28/07, Sick Monkey <[EMAIL PROTECTED]> wrote: I have just

Re: Creating a daemon process in Python

2007-02-23 Thread Nick Craig-Wood
see that in a daemonize recipe before? > else: > # time for child to die > os._exit(0) > else: > # wait for child to die and then bail > os.wait() > sys.exit() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: f---ing typechecking

2007-02-21 Thread Nick Craig-Wood
Delaney, Timothy (Tim) <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > > x += a > > > > does not equal > > > > x = x + a > > > > which it really should for all types of x and a > > Actually, this will *never* be t

Re: f---ing typechecking

2007-02-20 Thread Nick Craig-Wood
eError: can only concatenate list (not "tuple") to list >>> Ie x += a does not equal x = x + a which it really should for all types of x and a (That is the kind of statement about which I'm sure someone will post a perfectly reasonable counterexample ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Forking SocketServer daemon -- updating state

2007-02-20 Thread Nick Craig-Wood
by a dummy request, which seems a bit awkward. Can't you get SocketServer to timeout and return you control regularly? -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: 'import dl' on AMD64 platform

2007-02-19 Thread Nick Craig-Wood
John Pye <[EMAIL PROTECTED]> wrote: > On Feb 19, 6:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > John Pye <[EMAIL PROTECTED]> wrote: > > > application from running on the Debian Etch AMD64 platform. > > > It seems that the 'dl' mo

Re: 'import dl' on AMD64 platform

2007-02-18 Thread Nick Craig-Wood
nd for this -- perhaps another way to > access the values of those RTLD flags? Read stuff out of /usr/include/bits/dlfcn.h ? It seems to be a constant 1 anyway #define RTLD_LAZY 0x1 You could try compiling the dl module by hand. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http

Re: Calling J from Python

2007-02-10 Thread Nick Craig-Wood
it would be more elegant... >>> n = 1 >>> for i in range(16): ... print ("%X" % n).replace('0', ' ').replace('1', '*') ... n = n ^ (n << 4) ... * ** * * * * ** ** * * * * * * ** ** * * * * * * * * ** ** ** ** * * * * * * * * -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Finding cpu time spent on my program

2007-02-06 Thread Nick Craig-Wood
016001 >>> start = cpu_time(); f(); dt = cpu_time() - start; print dt 0.012001 >>> start = cpu_time(); f(); dt = cpu_time() - start; print dt 0.008001 You'll see the result is quantised to 4 ms (not sure what the .01 bits are about!) 4ms is the clock rate of this machine,

Re: assertions to validate function parameters

2007-01-27 Thread Nick Craig-Wood
ot; total = x power = x divisor = 1 old_delta = None while 1: power *= x power *= x power = -power divisor += 2 old_total = total total += power / divisor delta = abs(total - old_total) if old_delta is not None and

Re: How to use time.clock() function in python

2007-01-23 Thread Nick Craig-Wood
under windows you get a quite different result :- >>> from time import clock, time >>> print clock(), time() 7.54285810068e-006 1169574534.84 >>> print clock(), time() 3.32073322168 1169574538.16 >>> print clock(), time() 7.32428004118 1169574542.15

Re: mmap caching

2007-01-22 Thread Nick Craig-Wood
r there is something going on in your program that we don't know about or there is a bug somewhere, either in the OS or in python. Can you make a short program to replicate the problem? That will help narrow down the problem. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-

Re: mmap caching

2007-01-22 Thread Nick Craig-Wood
a MemoryError. It is asking for a new bit of memory and it is failing so it throws a MemoryError. Could memory allocation under windows be affected by a large chunk of mmap()ed file which is physically swapped in at the time of the allocation? -- Nick Craig-Wood <[EMAIL PROTECTED]> -- h

Re: mmap caching

2007-01-21 Thread Nick Craig-Wood
e written out if dirty and then dropped. The OS will try to keep hold of pages as long as possible just in case you need them again. The pages dropped should be the least recently used pages. I wouldn't have expected a MemoryError though... Did you do mmap.flush() after writing? -- Nick C

Re: Non-blocking pipes during subprocess handling

2007-01-09 Thread Nick Craig-Wood
t? You might want to check out this modification to subprocess which does non-blocking pipes. http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554 I personally think something like that should be built into subprocess -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.crai

Re: code optimization (calc PI) / New Algorithme for PI

2007-01-05 Thread Nick Craig-Wood
) def pi_ferguson(): return 4*(3*arctan(_1/4) + arctan(_1/20) + arctan(_1/1985)) def pi_hutton(): return 4*(2*arctan(_1/3) + arctan(_1/7)) def pi_gauss(): return 4*(12*arctan(_1/18) + 8*arctan(_1/57) - 5*arctan(_1/239)) def pi_euler(): return 4*(5*arctan(_1/7) + 2*arctan(_3/79))

Re: code optimization (calc PI)

2007-01-04 Thread Nick Craig-Wood
pi in 0.1 seconds and 10,000 digits in 20 seconds. """ Standalone Program to calculate PI using python only Nick Craig-Wood <[EMAIL PROTECTED]> """ import sys from time import time class FixedPoint

Re: Can I beat perl at grep-like processing speed?

2006-12-29 Thread Nick Craig-Wood
sys 0m0.068s > # I used python2.5 and perl 5.8.6 Playing for the other side temporarily, this is nearly twice as fast... $ time perl -lne 'print if m/destroy/oi' bigfile >pl.out real0m0.133s user 0m0.120s sys 0m0.012s vs $ time ./z.pl >pl.out.orig

Re: Convert Perl to Python

2006-12-29 Thread Nick Craig-Wood
conversions by hand. It is a bit tedious but a good editor with macros will let you fly through the job. I used emacs. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating all permutations from a regexp

2006-12-22 Thread Nick Craig-Wood
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > > A regular expression matcher uses a state machine to match strings. > > unless it's the kind of regular expression matcher that doesn't use a > state machine, like the one in Pyt

Re: Generating all permutations from a regexp

2006-12-22 Thread Nick Craig-Wood
achine generating all possible matches at each point. Luckily the python regexp matcher is written in python, so you have access to the state machine directly if you want. Take a look at sre*.py in the python library and you might be able to work out what to do! I had a brief look myself, and it looked

Re: Core dump revisited

2006-12-19 Thread Nick Craig-Wood
oto err; } label[i] = xstrdup(item_cstr); Py_DECREF(item); item = 0; [snip] err:; PyErr_Print(); out:; if (value) Py_DECREF(value); if (item) Py_DECREF(item); return rc; -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Core dump revisited

2006-12-19 Thread Nick Craig-Wood
as overwritten. Maybe it is a string you can identify... You'll also want to start reading the gdb manual on breakpoints and watchpoints at this moment! Find memory corruptions can be tricky and time consuming. Valgrind can help also. Good luck! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Core dump revisited

2006-12-18 Thread Nick Craig-Wood
not post the output. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to replace a comma

2006-12-18 Thread Nick Craig-Wood
ent and accurate style - this matches the next character which gets added back into the string. >>> re.sub(r",([^\s])", r", \1", s) 'One, Two, Three, Four, File' >>> This shows a fundamental difference between the two methods >>> t

Re: Serial port failure

2006-12-17 Thread Nick Craig-Wood
Rob <[EMAIL PROTECTED]> wrote: > Craig, > > In the embedded firmware, the each box re-transmits after it finishes > reading the packet. This is a very rudimentary system, and uses no > flow control. The topology is that each embedded box has a master and > a slave p

Re: Serial port failure

2006-12-15 Thread Nick Craig-Wood
ill tell you how to use it. I've broken a lot of serial port drivers with that program ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: shell command needs whitespace characters escaped

2006-12-08 Thread Nick Craig-Wood
): """Quote all the metacharacters in the args for the unix shell""" return " ".join([re.sub(r"([^A-Za-z0-9_])", r"\\\1", string) for string in args]) >>> print quotemeta(['a', "'b", 'c']) a \'b c > (or better, subprocess.call). A good idea! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Use of factory pattern in Python?

2006-12-07 Thread Nick Craig-Wood
not > limited to use the generic *args and **kw. If you don't want to use a register() function on each class you could introspect like this (untested) to make the registry :- registry = {} for obj in sys.modules[__name__].__dict__.values(): try: if issubclass(obj, Base):

Re: Mirror imaging binary numbers

2006-12-06 Thread Craig
Terry Reedy wrote: > "Craig" <[EMAIL PROTECTED]> wrote in message > news:[EMAIL PROTECTED] > > Thanks so much for the response. I have an array of individual bytes > > which will eventually make up a binary bitmap image that is loaded onto > > an LCD sc

Re: Mirror imaging binary numbers

2006-12-06 Thread Craig
Matimus wrote: > Craig wrote: > > I'm trying to switch binary numbers around so that the MSB becomes the > > LSB etc. > > What do you mean 'binary numbers'? They are all binary. If you mean the > int type, they are 32 bits long and there are 16 bit

Mirror imaging binary numbers

2006-12-06 Thread Craig
Hi there, I'm trying to switch binary numbers around so that the MSB becomes the LSB etc. Is there an easy way of doing this as I can't seem to find anything. If you could help that would be great. Thanks and good luck. Craig -- http://mail.python.org/mailman/listinfo/python-list

Re: how to invoke the shell command and then get the result in python

2006-12-06 Thread Nick Craig-Wood
uages like Python when used in a web environment. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Subprocess with a Python Session?

2006-12-05 Thread Nick Craig-Wood
p://pexpect.sourceforge.net/ >>> import pexpect >>> p = pexpect.spawn("python") >>> p.expect(">>>") 0 >>> p.sendline("print 10\n") 10 >>> p.readline() ' print 10\r\n' >>> p.readline() '10\r\n&

X11 bitmap image conversion problem

2006-12-05 Thread Craig
1000(0xBC). Is there an easy way to flip the bits after the im.tobitmap() conversion has been done or do I have to find another way? If you could help that would be greatly appreciated. Thanks and good luck. Craig -- http://mail.python.org/mailman/listinfo/python-list

Re: Opening colour BMPs with PIL

2006-12-05 Thread Craig
Fredrik Lundh wrote: > Craig wrote: > > > I'm trying to open colour BMPs using PIL and I'm getting the following > > errors. > > what program did you use to produce those BMP files? can you prepare > reasonably small samples using the same program and post

Re: how to invoke the shell command and then get the result in python

2006-12-05 Thread Nick Craig-Wood
o read the return code of the command and its stderr both of which you'll need if you are programming defensively! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Opening colour BMPs with PIL

2006-12-04 Thread Craig
packages\PIL\BmpImagePlugin.py", line 164, in _open self._bitmap(offset=offset) File "C:\python25\lib\site-packages\PIL\BmpImagePlugin.py", line 96, in _bitmap raise IOError("Unsupported BMP header type (%d)" % len(s)) IOError: Unsupported BMP header type (108) >>> I am using Windows XP with Python 2.5. I can open monochrome BMPs fine but I don't want that. If you could help that would be greatly appreciated. Thanks and good luck. Craig -- http://mail.python.org/mailman/listinfo/python-list

Convert PNG files to BMP files using PIL

2006-12-04 Thread Craig
can be used to fulfil the task. If you could let me know that would be great. Thanks and good luck. Craig -- http://mail.python.org/mailman/listinfo/python-list

Re: Ensure a variable is divisible by 4

2006-12-04 Thread Nick Craig-Wood
or x in range(0,12): (x + 3) & ~0x3 Which prints 0,4,4,4,4,8,8,8,8,12... You could also consider the funky x>>2<<2 -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: os.mkdir and mode

2006-12-04 Thread Nick Craig-Wood
Martin v. Löwis <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood schrieb: > > So it looks like python mkdir() is applying the umask where as > > /bin/mkdir doesn't. From man 2 mkdir > > Actually, mkdir(1) has no chance to not apply the umask: it also > has to us

Re: os.mkdir and mode

2006-12-04 Thread Nick Craig-Wood
os.mkdir() ? > > No, I didn't. What is the difference/advantage of that approach? If you use use os.umask(0) then the os.mkdir(dir, perms) will create the directory with exactly those permissions, no chmod needed. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: os.mkdir and mode

2006-12-02 Thread Nick Craig-Wood
st' Size: 4096Blocks: 8 IO Block: 4096 directory Device: 806h/2054d Inode: 2453906 Links: 2 Access: (0770/drwxrwx---) Uid: ( 518/ ncw) Gid: ( 518/ ncw) Access: 2006-12-02 09:48:04.0 + Modify: 2006-12-02 09:48:04.0 + Change: 2

Re: os.mkdir and mode

2006-12-02 Thread Nick Craig-Wood
mkdir() works just like its C equivalent, see > http://docs.python.org/dev/lib/os-file-dir.html: > > "Where it is used, the current umask value is first masked out." > > Use os.chmod() after os.mkdir() to get the desired permissions. I think you meant use os.umask(0) befor

Open 16-bit/24-bit windows bitmap using PIL

2006-11-30 Thread Craig
raise IOError("Unsupported BMP compression (%d)" % compression) IOError: Unsupported BMP compression (1) I can open a windows monochrome bitmap fine using PIL but the colour options are more desirable. I am using Windows 2000 if that is any help and I am saving the different BMP's using Microsoft Paint. If you could help that would be great. Craig -- http://mail.python.org/mailman/listinfo/python-list

Re: Wrapping A Shell

2006-11-29 Thread Nick Craig-Wood
quot;" end_time = time() + timeout output = "" while time() < end_time: try: output += p.stdout.read(1024) except IOError, e: if e.errno != EAGAIN: raise return output p.stdin.write("ls\n") print read_output(p) p.stdin.write("uname -a\n") print read_output(p) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Really closing stdout (was: "fork and exit" needed?)

2006-11-29 Thread Nick Craig-Wood
Mitja Trampus <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > I'm not sure how you do open stdout to /dev/null in python though! > > I suspect something like this... > > import posix > > posix.close(1) > > posix.open("/dev/null",

ElementTree xmlns:xsi question

2006-11-28 Thread Craig
ly. What can I do to make the code correct and the output being 100% correct as well. Any help would be greatly appreciated. Craig -- http://mail.python.org/mailman/listinfo/python-list

Re: "fork and exit" needed?

2006-11-28 Thread Nick Craig-Wood
Dennis Lee Bieber <[EMAIL PROTECTED]> wrote: > On Tue, 28 Nov 2006 04:30:09 -0600, Nick Craig-Wood > <[EMAIL PROTECTED]> declaimed the following in comp.lang.python: > > > > > If you run this > > > > import os,sys,time > > print

Re: "fork and exit" needed?

2006-11-28 Thread Nick Craig-Wood
eamonisation under unix. I'm not sure how you do open stdout to /dev/null in python though! I suspect something like this... import posix posix.close(1) posix.open("/dev/null", posix.O_WRONLY) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Generating header information using ElementTree

2006-11-26 Thread Craig
John Machin wrote: > Craig wrote: > > > Great. Got that sorted. The problem I have now is that some of the > > XML data is not copied across to the file when I have the text > > information included. The number of characters that is lost is equal > > to the numbe

Re: Generating header information using ElementTree

2006-11-26 Thread Craig
Diez B. Roggisch wrote: > Craig schrieb: > > Fredrik Lundh wrote: > > > >> Craig wrote: > >> > >>> I'm only new to Python so please bear with me. I using ElementTree to > >>> generate an XML file that will reference a DTD and an XSL

Re: Generating header information using ElementTree

2006-11-26 Thread Craig
Fredrik Lundh wrote: > Craig wrote: > > > I'm only new to Python so please bear with me. I using ElementTree to > > generate an XML file that will reference a DTD and an XSL file. The > > header information I want at the start of the file is as follows: > > &g

Generating header information using ElementTree

2006-11-26 Thread Craig
t find any documentation or examples on how you can do this. Any help would be appreciated. Thank you and good luck. Craig Williamson -- http://mail.python.org/mailman/listinfo/python-list

Re: pyserial port connection problem

2006-11-17 Thread Nick Craig-Wood
-th port? Also are you running as adminstrator? You may need admin rights to open a serial port under windows (I'm not sure). -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python-2.5.exe?

2006-11-15 Thread Nick Craig-Wood
helpful, eg @echo off set DEMOHOME=%CD% set PYTHONHOME=%DEMOHOME%\Python24 set PYTHONPATH=%PYTHONHOME%;%DEMOHOME%\Demo\Python set PYTHON=%PYTHONHOME%\python.exe set PYTHONW=%PYTHONHOME%\pythonw.exe set PATH=%PYTHONHOME%;%PATH% start "Demo" "%PYTHONW%" "demo.pyw"

Re: Using signal.alarm to terminate a thread

2006-11-15 Thread Nick Craig-Wood
es(): ... print "Running yes command..." ... pexpect.run('yes', timeout=5) ... >>> t = threading.Thread(target=runyes) >>> t.start() >>> Running yes command... t.join() [never returns] I'd guess at differences between the pexpect versions. You could try the pexpect from debian/testing easily enough I expect. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Using signal.alarm to terminate a thread

2006-11-14 Thread Nick Craig-Wood
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > > The only sensible things you can do from a signal handler is set a > > global flag, or call sem_post on a semaphore, to record the delivery > > of the signal. The remainder of the pr

Re: Using signal.alarm to terminate a thread

2006-11-14 Thread Nick Craig-Wood
ogram can then either poll the global flag, or use sem_wait() and sem_trywait() on the semaphore. Another option is to do nothing in the signal handler, and dedicate one thread (preferably the initial thread) to wait synchronously for signals, using sigwait(), and send messages to the other t

Re: Using signal.alarm to terminate a thread

2006-11-13 Thread Nick Craig-Wood
pexpect has a timeout parameter exactly for this case import os, pexpect, threading def runyes(): print "Running yes command..." pexpect.run('yes', timeout=5) t = threading.Thread(target=runyes) t.start() t.join() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to choose the right GUI toolkit ?

2006-11-10 Thread Nick Craig-Wood
look a lot nicer Eg debian ii gtk2-engines-gtk-qt 0.7-1 theme engine using Qt for GTK+ 2.x You get a control panel for GTK apps in the KDE control center also. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Nick Craig-Wood
Christophe <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood a écrit : > > There is also PyQT which we wrote off as we wanted to write commercial > > applications too. As it happens we have a commercial QT licence, but > > we decided we didn't want to have to

Re: Sorted list - how to change it

2006-11-09 Thread Nick Craig-Wood
7;hello') >>> random.shuffle(L) >>> L array('c', 'elohl') >>> L.tostring() 'elohl' Which is some way towards a mutable string... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to choose the right GUI toolkit ?

2006-11-09 Thread Nick Craig-Wood
QT licence, but we decided we didn't want to have to incurr the additional expense of renewing it. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: assigning values in __init__

2006-11-07 Thread Nick Craig-Wood
>>> You can then add to attributes in the subclasses class MagicCharacter(Character): attributes = Character.attributes | set(['spells', 'wand']) >>> MagicCharacter('name', strength=10, dexterity=5, intelligence=3, luck=0, spells=1)

Re: Sorted and reversed on huge dict ?

2006-11-04 Thread Nick Craig-Wood
* resource.getpagesize() ... >>> print memory_used() 4575232 >>> a=1000*"x" >>> print memory_used() 14577664 >>> If anyone knows a (unix) portable way of doing this I'd be interested! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: __div__ not recognized automatically

2006-11-02 Thread Nick Craig-Wood
def __str__(self): return "%s(%s)" % (self.__class__.__name__, self.value) a = NumX(4) b = NumX(2) print a,b print a+b print (a+b)/2 This prints ---- Nu

Re: Ok. This IS homework ...

2006-10-16 Thread Nick Craig-Wood
appropriate maps for the modern computing language territory. I was born and bred on flow charts and I admit they were useful back in the days when I wrote 1000s of lines of assembler code a week. Now-a-days a much better map for the the territory is pseudo-code. Python is pretty much executable pseudo-

Re: wx.grid question (trying to use code from Grid_Example.py)

2006-10-16 Thread Nick Craig-Wood
7;m just learning!). http://www.wxpython.org/maillist.php -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: IDE that uses an external editor?

2006-10-16 Thread Nick Craig-Wood
major-mode. Syntax colouring, indentation that sort of thing. There is also IM-Python for code navigation, and bycycle repair man for refactoring support. You can run stuff at the interactive python prompt from within emacs. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Thread termination

2006-10-14 Thread Nick Craig-Wood
ing to search for... ctypes.pythonapi.PyThreadState_SetAsyncExc -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: building extensions for Windows Python

2006-10-13 Thread Nick Craig-Wood
-the-box'. Neither of those statements are true. It is fairly easy to build python extensions using mingw hosted on linux which work with the standard python.org install - see my other post in this thread. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://

Re: building extensions for Windows Python

2006-10-13 Thread Nick Craig-Wood
ensions with mingw under linux, using -lpython2.4 which will run under windows. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Sending binary pickled data through TCP

2006-10-13 Thread Nick Craig-Wood
\\n, \\t and \\any_char into CR, LF, TAB and any_char""" def _translate(m): return m.group(1).translate(_unescape_mapping) return _unescape_re.sub(_translate, s) (These functions have been through the optimisation mill which is why they may not look immediately like how you might first think of writing them!) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: What value should be passed to make a function use the default argument value?

2006-10-04 Thread Nick Craig-Wood
urn var * 2 > But yes, defining a sentinel like this is a good idea. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: What value should be passed to make a function use the default argument value?

2006-10-04 Thread Nick Craig-Wood
late to ''. None is the traditional value to use for value not present, then you'd get this for the function def mainFunction(var, template=None): if template is None: template = 'base' And this for the calling bit if not_set_properly(template): template = None return mainFunction(var, template) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python to use a non open source bug tracker?

2006-10-04 Thread Nick Craig-Wood
n python. http://svn.mythtv.org/trac/ A nice extra is that it is written in python. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: DAT file compilation

2006-10-02 Thread Nick Craig-Wood
and .jar, and openoffice and all of its many extensions. If you are feeling really paranoid then encrypt it. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: builtin regular expressions?

2006-10-02 Thread Nick Craig-Wood
Moreover match becomes a string method. No need for extra importing > re and applying re.compile(). Both can be done in str.match() if > necessary. I'm happy with the re module. Having transitioned from perl to python some time ago now, I find myself using many fewer regexps due to the much better built in string methods of python. This is a good thing, because regexps should be used sparingly and they do degenerate into line noise quite quickly... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ruby %w equivalent

2006-09-27 Thread Nick Craig-Wood
Duncan Booth <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > In python when making __slots__ or module.__all__ you end up typing > > lists of objects or methods and they turn out like this which is quite > > a lot of extra typ

Re: ruby %w equivalent

2006-09-27 Thread Nick Craig-Wood
) which is nearly as neat as qw//, but not quite since the split() bit comes at the end so it doesn't notify you that you have an array of strings rather than a string. I don't expect a replacement for %w{}, qw// to ever be added to python, it is not the python way. And the python way is why I am now a python programmer not a perl programmer! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: R.S.I. solutions?

2006-09-26 Thread Nick Craig-Wood
ds just fine. RSI is a complicated disease - there are lots of different forms of it all caused by different things. You'll need some professional advice to sort it out. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: best way of testing a program exists before using it?

2006-09-12 Thread Nick Craig-Wood
on-dev about what you've done Thats what I've done in the past anyway! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: best way of testing a program exists before using it?

2006-09-12 Thread Nick Craig-Wood
s return False for X_OK under > Win32. I'm happy to submit the patch, but is it worth it? Wouldn't returning X_OK as true if the file exists be more sensible? Ie the file might be executable, you'll have to try it, rather than, no this file is definitely not executable... -

Re: best way of testing a program exists before using it?

2006-09-12 Thread Nick Craig-Wood
Tim Golden <[EMAIL PROTECTED]> wrote: > [Nick Craig-Wood] > > | Tim Golden <[EMAIL PROTECTED]> wrote: > | > if os.path.isfile (filepath): > | >print filepath > | > | You might get a more accurate result using > | > | os.

Re: best way of testing a program exists before using it?

2006-09-12 Thread Nick Craig-Wood
Tim Golden <[EMAIL PROTECTED]> wrote: > if os.path.isfile (filepath): >print filepath You might get a more accurate result using os.access(filepath, os.X_OK) instead of os.path.isfile(filepath) Which checks the file is executable -- Nick Craig-Wood <[

Re: A cross platform systray icon

2006-09-11 Thread Nick Craig-Wood
N/Cookbook/Python/Recipe/475155 Thanks anyway -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: A cross platform systray icon

2006-09-11 Thread Nick Craig-Wood
TheSeeker <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > Does anyone have some hints / tips / experience with making a cross > > platform systray icon? It should work on Windows, Gnome and KDE at > > minimum. > You might do a search for TaskBarIcon in th

<    1   2   3   4   5   6   7   8   9   >