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: 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: 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: 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: __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: 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: 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: 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: 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
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: 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: 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: 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-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-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: 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: Best way to check that a process is running on a Unix system?

2006-06-05 Thread Nick Craig-Wood
, []).append(process) for process in self.by_pid.values(): try: parent = self.by_pid[process.parent_pid] #print "child",process #print "parent",parent parent.children.append(process)

Re: how to switch from os.tmpnam to os.tmpfile

2006-06-08 Thread Nick Craig-Wood
ect Create a temporary file with no directory entries. Have a look at the functions in the tempfile module, mkstemp() in particular (the posix way), or NamedTemporaryFile() http://docs.python.org/lib/module-tempfile.html -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://

Re: os.link makes a copy, not a link

2006-06-10 Thread Nick Craig-Wood
tell whether you have a copy or a hardlink. >>> import os >>> file("z", "w").write("test") >>> os.link("z", "z2") >>> os.stat("z").st_ino 1685186L >>> os.stat("z2").st_ino 1685186

Re: os.link makes a copy, not a link

2006-06-10 Thread Nick Craig-Wood
our system, might copy the > file. The link(2) system call on linux never does that. Eg >>> import os >>> file("z", "w").write("test") >>> os.link("z", "/dev/shm/z") Traceback (most recent call last): File "", line 1, in ? OSError: [Errno 18] Invalid cross-device link >> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: help() on stdout.closed

2006-06-21 Thread Nick Craig-Wood
closed' bool indicating the current state of the file object. This is a read-only attribute; the `close()' method changes the value. It may not be available on all file-like objects. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Time out question

2006-07-03 Thread Nick Craig-Wood
ested #9a", True, 4, _test_time_limit, "nested #9b", True, 5, _spin, 10) _test_time_limit("nested #10", False, 7, _test_time_limit, "nested #10a",False, 6, _test_time_limit, "nested #10b",True, 5, _spin, 10) #_test_time_limit("nested #11", False, 7, _test_time_limit, # "nested #11a",True, 4, _test_time_limit, # "nested #11b",False, 10, _spin, 5) _test_time_limit("nested #12", False, 7, _test_time_limit, "nested #12a",False, 6, _test_time_limit, "nested #12b",False, 10, _spin, 5) print "All tests OK" test() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Problem when import C model

2006-07-03 Thread Nick Craig-Wood
If you want 64 bit choose -m64, eg echo <<'#END' >z.c #include int main(void) { printf("Hello\n"); return 0; } #END gcc -c -m32 -o z32.o z.c gcc -c -m64 -o z64.o z.c file z*.o gives z32.o: ELF 32-bit LSB relocatable, Intel 80386, version 1 (SYSV), not stripped z64

Re: Time out question

2006-07-04 Thread Nick Craig-Wood
Grant Edwards <[EMAIL PROTECTED]> wrote: > On 2006-07-03, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Alex Martelli <[EMAIL PROTECTED]> wrote: > >> DarkBlue <[EMAIL PROTECTED]> wrote: > >> > try for 10 seconds > >> >if d

Re: defining multi dimensional array

2006-07-05 Thread Nick Craig-Wood
for y in range(3): ... a[x][y] = i ... i = i + 1 ... >>> print a[1][1] 5 >>> a[2][1] = 'hello' >>> print a [[1, 2, 3], [4, 5, 6], [7, 'hello', 9], [10, 11, 12]] Numeric/scipy/numpy/whatever-it-is-called-today supports multidimensional arrays too I think and that may be more appropriate if you are doing heavy numerical work. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Fork You.. Forking and threading..

2006-07-05 Thread Nick Craig-Wood
p://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/66012 That releases the controlling terminal from your job and it exits from the process group. You could probably close / redirect stdin/out/err too. Search for daemonize.py and you'll find a module which does all this. --

Re: Tkinter problem

2006-07-08 Thread Nick Craig-Wood
o.1 => /lib/tls/i686/cmov/libnsl.so.1 (0xb7aa9000) libdl.so.2 => /lib/tls/i686/cmov/libdl.so.2 (0xb7aa5000) /lib/ld-linux.so.2 (0x8000) If there are any missing things then you need to re-install those packages. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-woo

Re: Can Python do Perl's print <

2006-08-24 Thread Nick Craig-Wood
this using stdin >>> cmds="""read A ... read B ... read C ... echo $C $B $A""" >>> out = Popen(cmds, shell=True, stdin=PIPE) >>> out.communicate("""one ... two ... three""") three two one (None, None) >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Best Practices for Python Script Development?

2006-08-25 Thread Nick Craig-Wood
es of the language, but otherwise it is a solid book with lots of good stuff in. The section on programming with TK is very good too - I keep coming back to that section. ... I'd recommend the first and the last from your list to start with, "Dive into Python" and "Progr

Re: IronPython on Mono howto

2006-09-07 Thread Nick Craig-Wood
user0m1.000s sys 0m0.036s $ time python2.4 -c pass real0m0.015s user0m0.008s sys 0m0.007s Over all I'm very impressed - it is great to have a new implemention of Python. I'm not sure mono is showing it off to its full extent though! -- Nick Crai

Re: xmingw and f2py

2006-09-08 Thread Nick Craig-Wood
svc/bin/dlltool --dllname python24.dll --def python24.def --output-lib libpython2.4.a # Move the files into the correct place mv -i python24.dll python24.def libpython2.4.a /usr/i586-mingw32msvc/lib/ After that lot you can build python extensions with mingw under linux, using -lpython2.4 -- Nick Cra

Re: xmingw and f2py

2006-09-08 Thread Nick Craig-Wood
27;t help you there. You want to tell distutils that the compiler is just gcc somehow and takes the same options. Not sure how you do that. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

A cross platform systray icon

2006-09-11 Thread Nick Craig-Wood
d like someone to tell me that PyQT, tkinter or PyGTK does it all for me, but from my searching on the subject I doubt it is going to be that easy! Thanks -- 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

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: 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: 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
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
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: 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: 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: 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: 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: 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: 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: 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: 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: 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: "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: "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: 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",

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: 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

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 +0000 Modify: 2006-12-02 09:48:04.0 + Change: 2

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-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: 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: 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

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&

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: 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: 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: Serial port failure

2006-12-15 Thread Nick Craig-Wood
to lock up the kernel mode serial driver. If it does lock up it is a driver bug. Here you'll find a little program I wrote which, with the help of a loopback connector, you can check your serial port out http://www.craig-wood.com/nick/pub/cambert.exe Run the program from a cmd prompt and it w

Re: Serial port failure

2006-12-17 Thread Nick Craig-Wood
oes lock up it is a driver bug. Here you'll find a little program I wrote which, with the help of a loopback connector, you can check your serial port out http://www.craig-wood.com/nick/pub/cambert.exe Run the program from a cmd prompt and it will tell you how to use it. I've broken a lot

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: 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: 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-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: 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: 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: 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: 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 user0m0.120s sys 0m0.012s vs $ time ./z.pl >pl.out.orig

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: 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: 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: Another try at Python's selfishness

2006-02-04 Thread Nick Craig-Wood
n the class and the local variables. The compiler doesn't warn about this - its perfectly legal C++. In a lot of big C++ programs various conventions are used to try to help with this - naming all parameters to functions _name rather than name, or using this->member rather than member. T

Re: pythonic exec* spawn*

2006-02-13 Thread Nick Craig-Wood
c/2.4.2/lib/module-subprocess.html You'll probably find threading easier though. http://www.python.org/doc/2.4.2/lib/module-threading.html But it will use your multiple CPUs less efficiently than fork()-ing. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: changing value of 'self' when subclassing int

2006-02-21 Thread Nick Craig-Wood
__(self): # FIXME is there a way to convert a long to binary? content = "" if self.i: L = [] i = self.i while i: L.append(int(i & 1L)) i >>= 1 L.reverse() content = str(L)

Re: Pyserial never read

2006-02-21 Thread Nick Craig-Wood
luca72 <[EMAIL PROTECTED]> wrote: > Thanks for your help, but it don't solve the problem. > I receive only the echo and full stop. Try swapping pins 2 and 3 in the lead. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/

Re: Pyserial never read

2006-02-21 Thread Nick Craig-Wood
Peter Hansen <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > luca72 <[EMAIL PROTECTED]> wrote: > > > >> Thanks for your help, but it don't solve the problem. > >> I receive only the echo and full stop. > > > > Try swapping

instances from bound methods

2006-03-02 Thread Nick Craig-Wood
yfile","w") >>> fn=fd.write >>> fn.im_self Traceback (most recent call last): File "", line 1, in ? AttributeError: 'builtin_function_or_method' object has no attribute 'im_self' >>> fn.__self__ >>> I wonder why? Is there a canonical way of doing it? -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: do design patterns still apply with Python?

2006-03-03 Thread Nick Craig-Wood
d be a little better > able to use them appropriately. ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: BitKeeper for Python?

2005-05-02 Thread Nick Craig-Wood
t; all the changes and be able to determine what parts of the code were > changed. > > If it were opensource that would be even better. You could try Mercurial http://www.selenic.com/mercurial/ which aims at being a true bk replacement. Its also written in python. Its being deve

Re: Adding tuples to a dictionary

2007-06-01 Thread Nick Craig-Wood
10 0.39 11 0.4 12 0.4 13 0.39 14 0.4 15 0.4 16 0.39 17 0.4 18 0.39 19 0.41 Note the first iteration is slower as it builds the tuple cache -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python memory handling

2007-06-01 Thread Nick Craig-Wood
retched up to 4k and M_MMAP_THRESHOLD was set to 4k then you'd have the perfect memory allocator... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Detecting an active exception

2007-06-03 Thread Nick Craig-Wood
rying to achieve and we can see if we can come up with a more pythonic solution? The fact that you are running into limits of the language like this as a new python programmer probably means you aren't thinking in python yet. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Non-blocking subprocess call

2007-06-04 Thread Nick Craig-Wood
rceforge.net/ Doesn't work on windows. Looks like you are doing OS X though so should work fine there -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Comments appreciated on Erlang inspired Process class.

2007-06-04 Thread Nick Craig-Wood
finished or not, and no way to wait on more than one Process() at once. If there is an exception then you should return it to the parent (see the subprocess module for an example). -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: subprocess leaves child living

2007-06-05 Thread Nick Craig-Wood
d deliver SIGPIPE to the child which may (or may not) kill it. At least it got some sort of notification. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Bug/Weak Implementation? popen* routines can't handle simultaneous read/write?

2007-06-07 Thread Nick Craig-Wood
here some place I can > submit this as a feature request? (Python dev?) The non-blocking subprocess would make a good start for a stdlib submission. It should really optionally use ptys under unix too otherwise you'll never be able to script passwd etc. An interface a bit like pexpect wpuld be useful too (ie scan for these regexps or timeout and return a match object). -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Bug/Weak Implementation? popen* routines can't handle simultaneous read/write?

2007-06-08 Thread Nick Craig-Wood
oriented buffer. You don't want block buffering > on interactive applications. Pty's probably aren't needed on Windows. BTW I'd love to see pexpect working on windows and also in the standard library. It is the proper answer to controlling other interactive processes IMHO. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Bug/Weak Implementation? popen* routines can't handle simultaneous read/write?

2007-06-09 Thread Nick Craig-Wood
dmoore <[EMAIL PROTECTED]> wrote: > On Jun 8, 12:30 pm, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Windows has a really strange idea of non-blocking IO - it uses > > something called overlapped io. You or in the FILE_FLAG_OVERLAPPED > > flag when you create

Re: avoid script running twice

2007-06-18 Thread Nick Craig-Wood
e() >>> open('lock.txt').read() 'ho' >>> The best cross platform way to create a lock is creating a directory. It is atomic on both windows and linux anyway. try: os.mkdir("lock") except OSError: print "locked!" else: try: do_stuff() finally: os.rmdir("lock") (untested) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: avoid script running twice

2007-06-18 Thread Nick Craig-Wood
You need flock under unix (this recipe shows windows flock equivalent also) http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/65203 or use the directory idea I posted in another post. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: avoid script running twice

2007-06-18 Thread Nick Craig-Wood
ix locking method. Note that it may not work if you are writing the lock file to an NFS mount! Traditionally you write your os.pid() to the file also. You can then send a signal to the running copy, detect stale lock files etc. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: avoid script running twice

2007-06-18 Thread Nick Craig-Wood
Tim Williams <[EMAIL PROTECTED]> wrote: > On 18/06/07, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > On Windows the open-a-file-for-writing method works well, but as *nix > doesn't work the same way then maybe the socket solution is the best > cross-platform option

Re: Using a switch-like if/else construct versus a dictionary?

2007-06-19 Thread Nick Craig-Wood
ch seperate "type" a seperate class type and implement the methods for each one. All the switches will disappear from your code like magic! Post more details if you want more help! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python/C API bug (multithreading)

2007-06-20 Thread Nick Craig-Wood
ceforge.net/tracker/index.php?func=detail&aid=1163563&group_id=5470&atid=105470 > Is there any simple way to fix this damned bug?? Locking, locking and more locking ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: configparser shuffles all sections ?

2007-06-22 Thread Nick Craig-Wood
(defaults) self._sections = odict() self._defaults = odict() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: automatical pdf generating

2007-06-25 Thread Nick Craig-Wood
3.jpg 4.jpg 01.pdf Which resizes each image to a max dimension of 1000 pixels and then tiles them into a PDF. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

<    9   10   11   12   13   14   15   16   17   18   >