Re: with timeout(...):

2007-03-27 Thread Nick Craig-Wood
interrupt. It may be possible - under unix you'd send a signal - which python would act upon next time it got control back to the interpreter, but I don't think it would buy us anything except a whole host of problems! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: with timeout(...):

2007-03-28 Thread Nick Craig-Wood
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > "Nick Craig-Wood" <[EMAIL PROTECTED]> wrote: > > Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > > > But would be useful to be able to do without messing with > > > threads and GUI

Re: with timeout(...):

2007-03-29 Thread Nick Craig-Wood
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > "Nick Craig-Wood" <[EMAIL PROTECTED]> wrote: > > > Well, yes there are different levels of potential reliability with > > different implementation strategies for each! > > Gadzooks! F

Re: with timeout(...):

2007-03-29 Thread Nick Craig-Wood
lp you, as you are single-threaded here. The > released lock won't prevent the called C-code from taking as long as it > wants. |And there is nothing you can do about that. I'm assuming that the timeout function is running in a thread... -- Nick Craig-Wood <[EMAIL PROTECTED

Re: with timeout(...):

2007-03-31 Thread Nick Craig-Wood
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > "Nick Craig-Wood" <[EMAIL PROTECTED]> wrote: > > > I'd like there to be something which works well enough for day to day > > use. Ie doesn't ever wreck the internals of python. It could ha

Re: with timeout(...):

2007-03-31 Thread Nick Craig-Wood
John Nagle <[EMAIL PROTECTED]> wrote: > Diez B. Roggisch wrote: > > Nick Craig-Wood wrote: > > > > > >>Did anyone write a contextmanager implementing a timeout for > >>python2.5? > >> > >>And have it work reliably and in a c

Re: Python Feature Request: Allow changing base of member indices to 1

2007-04-15 Thread Nick Craig-Wood
ramming Perl" that Larry Wall said it was a serious mistake to add this feature to perl. If it is a feature too far for perl then it is *definitely* a feature too far for python ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: subprocess confusion

2007-04-17 Thread Nick Craig-Wood
use of preexec_fn is preexec_fn=os.setsid You seem to be thinking it is pre-pending something to your command line which isn't how it works. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: [Tutor] Finding prime numbers

2007-09-20 Thread Nick Craig-Wood
y.is_prime(2**607-1) 1 >>> gmpy.is_prime(2**608-1) 0 Cheating perhaps! Note is_prime will be a probabalistic test for large numbers... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: compile for ARM

2007-09-20 Thread Nick Craig-Wood
er qemu and do native builds. Cross compilers work well though - we build our app which has python embedded for ARM using a cross compiler running under debian. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: unittest tutorial

2007-09-20 Thread Nick Craig-Wood
Gigs_ <[EMAIL PROTECTED]> wrote: > does anyone know some good tutorial for unittest? (with examples > how unit work)? There is one in Dive into Python http://www.diveintopython.org/unit_testing/index.html Buy the book is my advice! -- Nick Craig-Wood <[EMAIL PROTECTED]> -

Re: Google and Python

2007-09-24 Thread Nick Craig-Wood
Unix Environment) needed to implement it is rather disconcerting! A python module to do it would be great! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Google and Python

2007-09-26 Thread Nick Craig-Wood
ntry point to the local LAN, but would be harder to do > if there are two points of entry, and packets could hit from > outside on either.. It is all done in the kernel. The kernel has the state of the TCP connection - it is just accessed from a different process. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Using fractions instead of floats

2007-10-01 Thread Nick Craig-Wood
>>> mpq(1,3)+0.6 mpq(14,15) >>> mpq(5,2) mpq(5,2) >>> mpq(1,3)*mpq(6,10)*mpq(4,10)+mpq(7,8) mpq(191,200) >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Cross platform way of finding number of processors on a machine?

2007-10-05 Thread Nick Craig-Wood
> processor families are truly multi-core, and which are HT. On any unix/posix system (OSX and linux should both qualify) you can use >>> import os >>> os.sysconf('SC_NPROCESSORS_ONLN') 2 >>> (From my Core 2 Duo laptop running linux) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Cross platform way of finding number of processors on a machine?

2007-10-06 Thread Nick Craig-Wood
raise NotImplementedError There is a bug in that code... NotImplementedError will never be raised because num won't have been set. It will raise "UnboundLocalError: local variable 'num' referenced before assignment" instead -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: changes on disk not visible to script ?

2007-10-08 Thread Nick Craig-Wood
ode, plus a sequence of steps to be followed to replicate the problem and you'll get some real help. The above is just too vague. The above code has a syntax error in it so obviously isn't from working code. PS I really doubt the problem is windows not seeing the created file... -- Nick

Re: changes on disk not visible to script ?

2007-10-08 Thread Nick Craig-Wood
've actually typed "f.close" rather > > than "f.close()", > > You are right, I forgot the () in f.close() ! > thanks for pointing that out. > > VB programmer!? Thats really harsh.. I used to make that mistake a lot as an ex-perl programmer.

Re: Cross-platform GUI development

2007-10-12 Thread Nick Craig-Wood
application in Qt on Mac, Win or Linux look like a > native app. I'd recommend wxPython over those becase 1) native look and feel on all platforms 2) doesn't require expensive licensing for non-commercial apps (QT) 3) Isn't a pain to install on windows (GTK) That said, times change an

Re: Iteration for Factorials

2007-10-24 Thread Nick Craig-Wood
return math.exp(-n)*(n**(n-0.5))*math.sqrt(2*math.pi)*(1. + 1./12/n + 1./288/n**2 - 139./51840/n**3) Works for non integer factorials also... See here for background http://mathworld.wolfram.com/StirlingsSeries.html -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.cr

Re: bug: subprocess.Popen() hangs

2007-10-26 Thread Nick Craig-Wood
e a program to demonstrate the problem? You are best off reporting bugs here - then they won't get lost! http://bugs.python.org/ -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: cron, python and samba restart

2007-10-29 Thread Nick Craig-Wood
etty > > Removing this (or just disabling it for the user who must run the > cron job) should eliminate the error. Note that you will also need > to disable authentication either via the NOPASSWD tag or the > "authenticate" Defaults option. Check the PATH in cron also --

Re: Iteration for Factorials

2007-10-30 Thread Nick Craig-Wood
: number = myNumer[:] random.shuffle(number) if number == myNumer: count+=1 -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

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: 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-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: 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: 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: 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: 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: '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: '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: 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: 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: 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: 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: Low-overhead GUI toolkit for Linux w/o X11?

2007-11-04 Thread Nick Craig-Wood
r own GUI in pygame to do exactly what you want for your embedded device. > I'm not really sure what the differences are between those two. The > latter seems to be a little more active. Pygame is the way I've always done SDL stuff in python - never even heard of PySDL! -

Re: Creating Installer or Executable in Python

2007-11-15 Thread Nick Craig-Wood
p I've used py2exe and nsis quite a few times - works well. Note that py2exe can bundle your app into a single exe which you can just run which may be good enough (no need for an installer). -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Which uses less memory?

2007-11-17 Thread Nick Craig-Wood
instances (about 1,000,000 in our case) and adding __slots__ to it! I'd guess that if you __slot__-ed the Domain class then you'll find the overhead of a type attribute is minimal (4 bytes per instance I think). No idea about Hessian or Stomp (never heard of them!) but classes with __s

Re: import pysqlite2 or import sqlite3?

2007-11-25 Thread Nick Craig-Wood
, "credits" or "license" for more information. >>> from sqlite3 import dbapi2 >>> import sqlite3 >>> set(dir(sqlite3)) ^ set(dir(dbapi2)) set(['__path__', 'dbapi2']) >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Subprocess and 16-bit FORTRAN

2007-11-25 Thread Nick Craig-Wood
python expect module to work around these problems. Unfortunately there isn't a windows version :-( You could try the non blocking subprocess modification here http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/440554 You could also try wx.Process and wx.Execute from wxPython. -- Nic

Re: spawning a process with subprocess

2007-11-27 Thread Nick Craig-Wood
ines += 1 total += len(line) print "Received %d lines of %d bytes total" % (lines, total) # Which runs like this on my machine $ python subprocess-shell-nb.py waiting on child... waiting on child... waiting on child... waiting

Re: trouble selling twisted

2007-11-27 Thread Nick Craig-Wood
latform (using a shared QT) and see how much extra RAM it uses. > is there an exaample of going thru a passworded proxy using twisted > client classes? i have trouble understanding how to adapt the > proxy example on page 58 in the twisted book to my needs. I advise looking at

Re: Equivalent of perl's Pod::Usage?

2007-12-10 Thread Nick Craig-Wood
quot;" print >>sys.stderr, globals()['__doc__'] print >>sys.stderr, error sys.exit(1) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: int vs long

2007-12-17 Thread Nick Craig-Wood
at > those few posted code lines. Actually any number >= 2**31 won't fit in a python int. >>> 2**31 2147483648L According to my headers DWORD is defined like this typedef unsigned long DWORD; So you might see longs returned when you expected ints if the result was >= 0x800. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: int vs long

2007-12-20 Thread Nick Craig-Wood
Hendrik van Rooyen <[EMAIL PROTECTED]> wrote: > "Nick Craig-Wood" wrote: > > So you might see longs returned when you expected ints if the result > > was >= 0x800. > > did you mean 0x8000 ? > > ;-) Yes - well spotted! -- Nick Crai

Re: Joining stdout & stderr of subprocess ?

2006-04-21 Thread Nick Craig-Wood
r stuff comes all after the stdout stuff. > How can I get ahold of all the out and err joined synchronously in the > order, it is created ? You need to either 1) change myapp to fflush() more often 2) investigate the python pty module to fool the app into thinking it is talking to a termi

Re: how to append to a list twice?

2006-04-21 Thread Nick Craig-Wood
t this: > > series = [x/2 for x in range(200, 1, -1)] That should be series = [x//2 for x in range(200, 1, -1)] to be "from __future__ import division" safe -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Generate a sequence of random numbers that sum up to 1?

2006-04-22 Thread Nick Craig-Wood
(spread) This is simpler, easier to prove correct and most likely quicker. def distribution(N=2): L = [ random.uniform(0,1) for _ in xrange(N) ] sumL = sum(L) return [ l/sumL for l in L ] spread = distribution(10) print spread print sum(spread) -- Nick Craig-Wood <[EMAIL PROTECTED

Re: Python's regular expression?

2006-05-08 Thread Nick Craig-Wood
i) m = Matcher() t = 'blue socks and red shoes' if m.search(r'(blue|white|red)', t): print "Colour:", m[1] elif m.search(r'(socks|tights)', t): print "Garment:", m[1] elif m.search(r'(boot|shoe|trainer)', t): print "

Re: Incrementally converting a C app to Python

2006-05-10 Thread Nick Craig-Wood
sn't look so scary as 5k-10k LOC in Python. I bet your C code doesn't have unit tests either... Make sure you write those as you are going along in Python. It will make more code, but it will give you a wonderful feeling of confidence that your code will actually work, and

Re: Tabs versus Spaces in Source Code

2006-05-17 Thread Nick Craig-Wood
esn't matter! > The following quote sums things up nicely I think: > > "In theory there is no difference between theory and practice, but in > practice there is." ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: a good explanation

2006-05-25 Thread Nick Craig-Wood
You might want to show him this too...if you happen to need cnt in the loop, this is what you write files = [a,b,c,d] for cnt, fi in enumerate(files): do_something(cnt, fi) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Why python says "unexpected parameter 'mini.py'" for my code?

2008-01-04 Thread Nick Craig-Wood
d I have to close it. > I cannot find the reason. Can somebody give me a hint to let it work > well? Thanks I tried it but it doesn't work at all on linux. I suggest you use wxPython and stop re-inventing the wheel! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wo

Re: "Canonical" way of deleting elements from lists

2008-01-09 Thread Nick Craig-Wood
>>> print a, b [5, 6, 7] [5, 6, 7] Using keywords[:] stops the creation of another temporary list. The other behaviour may or may not be what you want! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: "Canonical" way of deleting elements from lists

2008-01-09 Thread Nick Craig-Wood
Fredrik Lundh <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > > Using keywords[:] stops the creation of another temporary list. > > in CPython, "list[:] = iter" actually creates a temporary list object on > the inside, in case "iter"

Re: urllib2 rate limiting

2008-01-11 Thread Nick Craig-Wood
0118 kb downloaded 21.304672.1 kBytes/s Sleep for 0.497982025146 40 kb of 10118 kb downloaded 19.979510.1 kBytes/s Sleep for 0.497948884964 48 kb of 10118 kb downloaded 19.184721.1 kBytes/s Sleep for 0.498008966446 ... 1416 kb of 10118 kb downloaded 16.090774.1 kBytes/s Sleep for 0.499262094498 1424

Re: python recursive function

2008-01-11 Thread Nick Craig-Wood
ursion depth exceeded 16 16 maximum recursion depth exceeded 17 False [snip] 89 False 90 90 maximum recursion depth exceeded 91 False 92 False 93 93 maximum recursion depth exceeded 94 False 95 False 96 96 maximum recursion depth exceeded 97 False 98 False 99 99 maximum recursion depth exceeded -- N

Re: where do my python files go in linux?

2008-01-14 Thread Nick Craig-Wood
which becomes effectively part of the OS. The package manager tracks every file it installes to ensure ovewrites can't happen etc... /usr/local/bin is for stuff installed from source, not using the package manager. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Threaded server

2008-01-14 Thread Nick Craig-Wood
bject the ftphandler code relies on. I see you attempt to kill the ftp server with ftpd.stop(). That is good, but you don't wait for the thread to finish (it might take up to a second in ftpd.server_forever if I understand correctly). I expect if you put a self.join() at the end of the stop() method the problem will go away. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: where do my python files go in linux?

2008-01-14 Thread Nick Craig-Wood
> production of Debian packages using distutils. Looks interesting though! > [1] http://stdeb.python-hosting.com/ -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: A GUI framework for running simulations

2008-01-24 Thread Nick Craig-Wood
n't that hard). -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: piping into a python script

2008-01-25 Thread Nick Craig-Wood
ine) This iterates over the lines of all files listed in sys.argv[1:], defaulting to sys.stdin if the list is empty. If a filename is '-', it is also replaced by sys.stdin. To specify an alternative list of filenames, pass it as the first argument to input(). A single file name is also allowed. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: best(fastest) way to send and get lists from files

2008-02-05 Thread Nick Craig-Wood
or list size 1000 Read back 1000 items in 0.000352478027344 s Written 50005 bytes for list size 1 Read back 1 items in 0.00165479183197 s Written 55 bytes for list size 10 Read back 10 items in 0.0175776958466 s Written 505 bytes for list size 100 Read back 100 i

Re: Does anyone else use this little idiom?

2008-02-05 Thread Nick Craig-Wood
'dummy' would both be OK. As for me personally, I usually use '_' but sometimes use 'dummy' depending on the surrounding code. Note that this idiom is fairly common in python too wanted, _, _, _, also_wanted = a_list which looks quite neat to my eyes. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ways to declare empty set variable

2008-02-13 Thread Nick Craig-Wood
tances. The syntax isn't so great when you set things which aren't valid keywords though... eg { (1,2,3) : 'a', (4,5,6) : 'b' } vs dict([ ((1,2,3), 'a'), ((4,5,6), 'b') ]) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Garbage collection

2008-02-19 Thread Nick Craig-Wood
n__.Y object at 0xb7d9fc2c>] [<__main__.Y object at 0xb7d9fc8c>] (It behaves slightly differently in the interactive interpreter for reasons I don't understand - so save it to a file and try it!) In fact I find most of the times I wanted __del__ can be fixed by using a weakref.WeakValueDictionary or weakref.WeakKeyDictionary for a much better result. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding Priority Scheduling feature to the subprocess

2008-02-22 Thread Nick Craig-Wood
20 job gets only 4%. I think you are on to a loser here trying to normalise it across OSes unfortunately :-( -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: Strangle 0.3.0 DNS parsing library based on BIND9

2008-02-25 Thread Nick Craig-Wood
this code? I looked at the examples but I couldn't see one? Having a simple nameserver written in python would be very useful indeed... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Adding Priority Scheduling feature to the subprocess

2008-02-25 Thread Nick Craig-Wood
TimeHorse <[EMAIL PROTECTED]> wrote: > On Feb 22, 4:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Interestingly enough this was changed in recent linux kernels. > > Process levels in linus kernels are logarithmic now, whereas before > > they weren'

Re: Writing Memory to File

2008-03-10 Thread Nick Craig-Wood
sing the ptrace interface. Both those things will require the relevant rights and neither is quite as easy as you might hope for! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python tricks

2009-01-13 Thread Nick Craig-Wood
above and the original proposal class InfiniteLoopError(Exception): """An 'infinite' loop has been detected""" def infinite_loop(max=200): for i in xrange(max): yield i raise InfiniteLoopError() Use it like this for i in infinite_loop(): if i > 10: break print "iteration", i or for i in infinite_loop(10): print "iteration", i > but I agree with Tim that a for ... else loop for the limit is > clearer. Probably yes -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ctype problem

2009-01-14 Thread Nick Craig-Wood
; Where is my fault? You didn't (or you didn't show) defining the argument types of the function. myclib = CDLL("myclib.so") # or whatever myclib.myfunction.argtypes = [ POINTER(INTERFACE) ] myclib.myfunction.restype = c_int # or whatever If you do that then you should be able to pass in myiface directly or byref(myiface). -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: initialising a class by name

2009-01-14 Thread Nick Craig-Wood
t): cls.registry[cls.__name__] = cls class ThingOne(BaseThing): pass class ThingTwo(BaseThing): pass class ThingThree(BaseThing): pass print BaseThing.registry["ThingOne"] print BaseThing.registry["ThingTwo"] print BaseThing.registry["ThingTh

Re: Python 2.6's multiprocessing lock not working on second use?

2009-01-19 Thread Nick Craig-Wood
Thread(target=test_lock_process, args=(lock,i,queue,))) for t in threads: t.start() for t in threads: t.join() if print_result: try: while True: print queue.get(block=False) except Empty: pass if __name__ == "__

Re: Python 2.6's multiprocessing lock not working on second use?

2009-01-19 Thread Nick Craig-Wood
ossible to fix to me. I'd love to be proved wrong though! If you were thinking of passing time.time() / clock_gettime(CLOCK_MONOTONIC) along in the Queue too, then you'll want to know that it can differ by significant amounts on different processors :-( Good luck! -- Nick Craig-Woo

Re: Code critique xmlrpclib

2009-02-03 Thread Nick Craig-Wood
t; raise Exception("Record not found") > > > def changeRecord(self, record, type, target): > """ > Changes a dns entry. > @param record: which record to chance > @param type: what type of record, A

Re: Code critique xmlrpclib

2009-02-04 Thread Nick Craig-Wood
flagg wrote: > On Feb 3, 7:32?am, Nick Craig-Wood wrote: > > flagg wrote: > > > ?This xmlrpc server is designed to parse dns zone files and then > > > ?perform various actions on said files. \ > > > ?It uses dnspython, and xmlrpclib > > > ? I

Re: Cross platform compilation?

2009-02-04 Thread Nick Craig-Wood
t. It then uses that new compiler to compile a gcc for the target architecture. I could imagine a similar scheme for python, but it would involve lots of fiddling about and some commitment from the python maintainers. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: MySQLdb and MySQL stored functions

2009-02-04 Thread Nick Craig-Wood
kurt.forrester@googlemail.com wrote: > Any ideas on how to suppress the warning output: > __main__:1: Warning: No data - zero rows fetched, selected, or > processed You can use the warnings module to suppress these I would have thought. -- Nick Craig-Wood -- http://www.craig

Re: Escaping my own chroot...

2009-02-11 Thread Nick Craig-Wood
debian, ubuntu and centos packages for it if you look! -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Escaping my own chroot...

2009-02-13 Thread Nick Craig-Wood
Jean-Paul Calderone wrote: > On Wed, 11 Feb 2009 09:31:56 -0600, Nick Craig-Wood > wrote: > >r0g wrote: > >> I'm writing a linux remastering script in python where I need to chroot > >> into a folder, run some system commands and then come out and do some

Re: String concatenation performance with +=

2009-02-14 Thread Nick Craig-Wood
moredata = "A"*4096 test = StringConcatTest() t = time.time() for i in range(1000): test.feed(moredata) print "%0.3f ms"%(1000*(time.time() - t)) Before it was 3748.012 ms on my PC, afterwards it was 52.737 ms However that isn't a perfect solution - what if something had anot

Re: encrypting lines from file with md5 module doesn't work?

2009-02-14 Thread Nick Craig-Wood
est:$1$3nvOlOaw$vRWaitT8Ne4sMjf9NOrVZ.:13071:0:9:7::: (not a real password line!) You need to work out how to write that format. >From memory: the "$1" bit means it is an md5 hash, the next "$3nvOlOaw$" is the salt and the final "$vRWaitT8Ne4sMjf9NOrVZ." is the m

Re: Easier to wrap C or C++ libraries?

2009-02-15 Thread Nick Craig-Wood
all platforms. I used to use > ctypes for wrapper but eventually I switched to Cython. What sort of problems have you had? I find as long as I use the same types as the C code actually uses it all works fine. If on a 64 bit platform long is 64 bits then it will be under ctypes too. -- Nick

Re: Found a very nice, small, cross-platform GUI toolkit for Python.

2009-02-16 Thread Nick Craig-Wood
tly the same on all supported platforms and since it usually runs full screen that is fine. I imagine this GUI toolkit fits the same niche. Presumably since it uses SDL then all the GUI will appear in one window? So windows within windows in the MDI style? -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Pythonic way to determine if a string is a number

2009-02-16 Thread Nick Craig-Wood
ibrary atof() does. Ie only converting as much as it can and returning 0.0 for an error. """ match = _float_pattern.search(value) if match: return float(match.group(1)) return 0.0 >>> atof("15.5 Sausages") 15.5 >>> atof(" 17.2")

Re: How do I declare global vars or class vars in Python ?

2009-02-20 Thread Nick Craig-Wood
t; return self._A def _setA(self, value): print "Setting A" self._A = value A = property(_getA, _setA) def main(self): print self.A print self.B # dosomething self.A = "aValue" self.B = "aValue" print self.A print self.B >>> a = Stuff() >>> a.main() Getting A None None Setting A Getting A aValue aValue >>> -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: can multi-core improve single funciton?

2009-02-23 Thread Nick Craig-Wood
fibonacci_noniterative(i) t_noniterative = time() - t0 print "%10d, %10.6f, %10.6f" % (i, t_iterative, t_noniterative) if f_iterative != f_noniterative: print "Calculation error" print "iterative", f_iterative print "non iterative", f_noniterative print "difference", f_iterative-f_noniterative -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Django Latex Permissions Problem

2008-11-25 Thread Nick Craig-Wood
is directory. I have a feeling that > pdflatex is trying to generate files using some weird access > credentials that dont have access to /tmp/pdfscratch{id} Unlikely - it takes root to change user and I wouldn't have thought any of the files would be setuid. Try chdir to /tmp/pdfscrat

Re: recommended __future__ imports for 2.5?

2008-11-25 Thread Nick Craig-Wood
'm still waiting to hear that > > from __past__ import division > > will become a reality... ;-) I think that is called using // instead of / which works without any from __future__ import from python 2.2 onwards. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to get a directory file descriptor?

2008-11-26 Thread Nick Craig-Wood
opendir(".") print "dir_p = %r" % dir_p dir_fd = dirfd(dir_p) print "dir_fd = %r" % dir_fd print "closed (rc %r)" % closedir(dir_p) Which prints on my linux machine dir_p = dir_fd = 3 closed (rc 0) I don't know why os doesn't wrap - opendir, cl

Re: distinct fcntl flags for stdin and stdout

2008-12-01 Thread Nick Craig-Wood
e 'r' at 0xb7d03020> fd=0 STDOUT ', mode 'w' at 0xb7d03068> fd=1 os.O_NDELAY=0800 stdin: flag=0002 stdout: flag=8001 setting non blocking on stdin... stdin: flag=0802 stdout: flag=8001 removing non blocking on stdin... stdin: flag=0002 stdout: flag=8001 So I suspect your result is because stdin and stdout refer to the same file (eg /dev/tty0 or /dev/pts/25). No idea whether this is correct behaviour or not though! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Do more imported objects affect performance

2008-12-01 Thread Nick Craig-Wood
uot; And here is the test again, actually calling something with the same difference in execution speed :- $ python -m timeit -s 'from os import nice' 'nice(0)' 100 loops, best of 3: 1.21 usec per loop $ python -m timeit -s 'import os' 'os.nice(0)' 100 loops, best of 3: 1.48 usec per loop -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Emacs vs. Eclipse vs. Vim

2008-12-01 Thread Nick Craig-Wood
im have all these features, don't know about Eclipse. In fact if I had to pick one feature that a programmer's editor must have it would be keyboard macros. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-01 Thread Nick Craig-Wood
e first time it will populate itself. If None is a valid value for data then make a sentinel, eg class PayloadOnDemand(object): sentinel = object() def __init__(self, a_file, a_file_position): self._data = self.sentinel self.f = a_file self.file_position = a_file_position @property def data(self): if self._data is self.sentinel: self._data = self.really_read_the_data() return self._data -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Do more imported objects affect performance

2008-12-02 Thread Nick Craig-Wood
bar.yourclass import YourClass If this spelling causes local name clashes, then spell them import myclass import foo.bar.yourclass and use "myclass.MyClass" and "foo.bar.yourclass.YourClass" Ultimately it is a matter of taste I think! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to instantiate in a lazy way?

2008-12-02 Thread Nick Craig-Wood
Slaunger <[EMAIL PROTECTED]> wrote: > On 2 Dec., 11:30, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > > > For 4 attributes I'd probably go with the __getattr__. > > > OK, I'll do that! > > > Or you could easily write

Re: How to instantiate in a lazy way?

2008-12-02 Thread Nick Craig-Wood
Slaunger <[EMAIL PROTECTED]> wrote: > On 1 Dec., 16:30, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > > I wouldn't use __getattr__ unless you've got lots of attributes to > > overload. ?__getattr__ is a recipe for getting yourself into trouble >

Re: Do more imported objects affect performance

2008-12-02 Thread Nick Craig-Wood
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Tue, 02 Dec 2008 11:12:31 +0000, Nick Craig-Wood wrote: > > > I prefer the "from module import function". That means that if "module" > > doesn't supply "function" it raises an

<    1   2   3   4   5   6   7   >