Re: Write bits in file

2008-05-20 Thread Nick Craig-Wood
be stored at an arbitrary > > bit-position in the file > > Yes. I need arbitrary, 8bits, than 10 bits for something else, than > sequence of bytes, than 10 bits again, etc. You could try http://construct.wikispaces.com/ which could well do exactly what you want. -- Nick Cr

Re: php vs python

2008-05-22 Thread Nick Craig-Wood
drummed into me to always use parameters for user input and I was really suprised PHP didn't have them. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Flaming Thunder

2008-05-22 Thread Nick Craig-Wood
8. 8 2> X = 10. ** exception error: no match of right hand side value 10 3> That error message is the erlang interpreter saying "Hey I know X is 8, and you've said it is 10 - that can't be right", which is pretty much what math teachers say too... -- Nick Craig-Wood <[EM

Re: Python and Flaming Thunder

2008-05-22 Thread Nick Craig-Wood
Mel <[EMAIL PROTECTED]> wrote: > Mensanator wrote: > > On May 22, 10:30??am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > >> Dave Parker <[EMAIL PROTECTED]> wrote: > >> > But after getting input from children and teachers, etc, it started > &g

Re: Python and Flaming Thunder

2008-05-23 Thread Nick Craig-Wood
L). I think candygram is crying out to be married with stackless &or PyPy. It also needs an IPC channel to compete with Erlang directly. If you are interested in stackless python vs Erlang then take a look at this... http://muharem.wordpress.com/2007/07/31/erlang-vs-stackless-python-a-first-

Re: Calling class method by name passed in variable

2008-05-23 Thread Nick Craig-Wood
nt call last): File "", line 1, in TypeError: 'int' object is not callable >>> getattr(obj, 'f')(1) False >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: call f(a, *b) with f(*a, **b) ?

2008-05-23 Thread Nick Craig-Wood
y manipulation)... So instead of f(a, *args) have f(a, list_of_args). The f(*args) syntax is tempting to use for a function which takes a variable number of arguments, but I usually find myself re-writing it to take a list because of exactly these sort of problems. In fact I'd be as bold to

Re: ctypes help

2008-05-23 Thread Nick Craig-Wood
4] OSCL_getCurrentStaticParams [ 5] OSCL_getErrorString [ 6] OSCL_getIdent [snip] This is a dll we used in a project, and those names exactly worked with ctypes, eg some snips from the ctypes code self.dll = cdll.LoadLibrary("OurSharedCodeLibrary") self.dll.OSCL_getErrorString.restype = c_char_p def getErrorString(self, status): return self.dll.OSCL_getErrorString(c_int(status)) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is math.pi slightly wrong?

2008-05-23 Thread Nick Craig-Wood
de("hex") '400921fb54442d18' >>> struct.unpack(">d", "400921FB54442D18".decode("hex")) (3.1415926535897931,) >>> struct.unpack(">d", "400921FB54442D19".decode("hex")) (3.1415926535897936,) >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Calling class method by name passed in variable

2008-05-23 Thread Nick Craig-Wood
Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood a ?crit : > > Bruno Desthuilliers <[EMAIL PROTECTED]> wrote: > >>> Can someone suggest an efficient way of calling method whose name is > >>> passed in a variable? > >>>

Re: Advice from senior Members

2008-05-23 Thread Nick Craig-Wood
t is hard to write tests for wx GUIs though (but not impossible). When you've finished you'll have 3 files full of classes. You may have a few utility functions too. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: array of 64-bit ints?

2008-05-23 Thread Nick Craig-Wood
this... from ctypes import * Array = c_int64 * 100 a = Array() for i in range(100): a[i] = 2**63 - i for i in range(100): print a[i] prints -9223372036854775808 9223372036854775807 9223372036854775806 [snip] 9223372036854775710 9223372036854775709 ctypes arrays are fixed len

Re: ctypes, function pointers and a lot of trouble

2008-05-28 Thread Nick Craig-Wood
an "Invalid Parameter" errorcode. there's also no useful > data whereas datainfo gets written correctly. I know that my cdStream > can't work, facing the C-code, but what'd be the right cdStream class? > What can I do? Any ideas? I've noted some obvious problems above. To get this to work will require some C knowledge. If they supply some example C code I'd work through that translating it line by line to python+ctypes. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ctypes, function pointers and a lot of trouble

2008-05-30 Thread Nick Craig-Wood
uint), ("open", cstreamopen), ("close", cstreamclose), # etc... This will involve you re-ordering your definitions. Or alternatively, you could cast the function pointer to a c_void_p first, eg data.u.pStream.open = c_void_p( c

Re: ctypes, function pointers and a lot of trouble

2008-06-02 Thread Nick Craig-Wood
call last): File "", line 1, in TypeError: expected LP_c_char instance, got _ctypes.PointerType >>> databuftype = c_char * 10 >>> databuf = databuftype() >>> cbuffer.cpBuffer = databuf >>> databuf <__main__.c_char_Array_10 o

Re: ctypes, function pointers and a lot of trouble

2008-06-04 Thread Nick Craig-Wood
> dwCreationDisposition, > FILE_ATTRIBUTE_NORMAL, > NULL ); use os.read os.write and os.open which will give you OS handles rather than python file objects, ie I think these are a fairly direct interface to CreatFile etc

Re: How to perform a nonblocking read from a process

2008-06-04 Thread Nick Craig-Wood
L or Expect nor does it require C extensions to be compiled. It should work on any platform that supports the standard Python pty module. The Pexpect interface was designed to be easy to use. You'll never get it to work with subprocess like this because of the buffering. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to kill a thread?

2008-06-07 Thread Nick Craig-Wood
com/ASPN/Cookbook/Python/Recipe/496960 and http://sebulba.wikispaces.com/recipe+thread2 Read the caveats! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: time.clock() or Windows bug?

2008-06-08 Thread Nick Craig-Wood
ion layer (HAL). To specify processor affinity for a thread, use the SetThreadAffinityMask function. I would have said time.time is what you want to use anyway though because under unix time.clock() returns the elapsed CPU time which is not what you want at all! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: time.clock() or Windows bug?

2008-06-09 Thread Nick Craig-Wood
Tim Roberts <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > > >time.clock() uses QueryPerformanceCounter under windows. There are > >some known problems with that (eg with Dual core AMD processors). > > > >See http://m

Re: time.clock() or Windows bug?

2008-06-09 Thread Nick Craig-Wood
Theo v. Werkhoven <[EMAIL PROTECTED]> wrote: > The carbonbased lifeform Nick Craig-Wood inspired comp.lang.python with: > > Theo v. Werkhoven <[EMAIL PROTECTED]> wrote: > >> Output: > >> Sample 1, at 0.0 seconds from start; Output power is: 8.967 dBm >

Re: Web Crawler - Python or Perl?

2008-06-09 Thread Nick Craig-Wood
but once you do you'll be writing a killer crawler ;-) As for Perl - once upon a time I would have done this with perl, but I wouldn't go back now! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: _POSIX_C_SOURCE

2008-06-09 Thread Nick Craig-Wood
SOURCE" > redefined > > but if i do > > export C_INCLUDE_PATH=/usr/include/python2.4 > > I do not face any compilation issues. > > I would like to know if there is anything i am missing on this. Do it in your code with #define _POSIX_C_SOURCE instead of the Makefile

Re: mysql to sqlite

2008-06-11 Thread Nick Craig-Wood
which was from MSSQL->MySQL). You'll find that different databases have subtly different ways of doing things (eg autoincrement fields on mysql) so you'll most likely need a custom script anyway. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Alternative to Decimal type

2008-06-11 Thread Nick Craig-Wood
.mpq(123,1000) >>> b = gmpy.mpq(12,100) >>> a+b mpq(243,1000) >>> a*b mpq(369,25000) >>> a/b mpq(41,40) >>> It is also *very* fast being written in C. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: get keys with the same values

2008-06-12 Thread Nick Craig-Wood
'e'] > 2 : ['c'] > 3 : ['b', 'd'] > 4 : ['f'] > Or use the little understood dict.setdefault method which has been with us from time immemorial... >>> d = {'a' : 1, 'b' : 3, 'c' : 2,'d' : 3,'e' : 1,'f' : 4} >>> dd = {} >>> for k, v in d.items(): ... dd.setdefault(v, []).append(k) ... >>> dd {1: ['a', 'e'], 2: ['c'], 3: ['b', 'd'], 4: ['f']} >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: sorted or .sort() ?

2008-06-16 Thread Nick Craig-Wood
expensive than computer time, > after all. Good advice with one caveat: sorted() was only introduced in python 2.4 so if your code must run on earlier versions then use list.sort() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to catch StopIteration?

2008-06-17 Thread Nick Craig-Wood
numerate(collatz(13)): ... last = x[:i+1] ... print x[:i+1] ... else: ... last.append(1) ... print last ... [13] [13, 40] [13, 40, 20] [13, 40, 20, 10] [13, 40, 20, 10, 5] [13, 40, 20, 10, 5, 16] [13, 40, 20, 10, 5, 16, 8] [13, 40, 20, 10, 5, 16, 8, 4] [13, 40, 20, 10, 5, 16, 8,

Re: how to export functions by name for ctype

2008-06-23 Thread Nick Craig-Wood
vention. I guess you've compiled your DLL with C++ and the above is a C++ mangled name. Either compile it with C, or export the names in an extern "C" { } block. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: flock seems very unsafe, python fcntl bug?

2008-06-23 Thread Nick Craig-Wood
if not os.path.exists('aaa'): fd = open('aaa', 'w+') else: fd = open('aaa', 'r+') fcntl.flock(fd,fcntl.LOCK_EX) fd.truncate() fd.write(data) fd.close() def check(): fd = open('aaa', 'r') fcntl.flock(fd,fcntl.LOCK_EX) data = fd.read() fd.close() if data not in ("sausage", "potato"): raise AssertionError("Wrong data %r" % data) if os.path.exists("aaa"): os.unlink("aaa") if len(sys.argv) < 2: print "Syntax: %s " % sys.argv[0] raise SystemExit(1) method = globals()["method_"+sys.argv[1]] if os.fork(): while 1: method("sausage") check() else: while 1: method("potato") check() -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: MD5 hash for url and utf unicode converting to ascii

2008-06-24 Thread Nick Craig-Wood
t;>> value '\xc9\x11}\x8f?64\x83\xf3\xcaPz\x1d!\xddd' >>> value.encode("hex") 'c9117d8f3f363483f3ca507a1d21dd64' >>> long(value.encode("hex"), 16) 267265642849753964132104960801656397156L >>> > For unicode encoding, I can do, md5.update(value.encode('utf-8')) to > give me ascii values. Yes that would be fine -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: binary representation of an integer

2008-06-24 Thread Nick Craig-Wood
out.append(hex_to_binary[hex_digit]) ... out = "".join(out).lstrip("0") ... if out == "": ... out = "0" ... return out ... >>> to_binary(0) '0' >>> to_binary(10) '1010' >>> to_binary(100) '1100100' >>> to_binary(1000) '101000' >>> to_binary(1000) '1000101011000111001000110100100010001000' But don't try this ;-) >>> to_binary(-1) Traceback (most recent call last): File "", line 1, in File "", line 4, in to_binary KeyError: '-' -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python 3000 vs Perl 6

2008-06-24 Thread Nick Craig-Wood
) Another VM to run python would be nice of course, but we already have jython, ironpython and pypy. Both jython and ironpython use JIT, pypy can compile to native code and you can use psyco for JIT code also in normal python. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig

Re: calling a .exe from Python

2008-06-24 Thread Nick Craig-Wood
robably what you want is this... from subprocess import call rc = call(["mypath/myfile.exe",arg1,arg2]) rc will contain the exit status See the subprocess module for more things you can do -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: shorten this: if char in "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz":

2008-06-25 Thread Nick Craig-Wood
t creates two lists then joins them then throws the whole lot away! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: calling a .exe from Python

2008-06-25 Thread Nick Craig-Wood
evidentemente.yo <[EMAIL PROTECTED]> wrote: > On 24 jun, 14:32, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Probably what you want is this... > > > > from subprocess import call > > > > rc = call(["mypath/myfile.exe",arg1,arg2])

Re: C++ or Python

2008-06-28 Thread Nick Craig-Wood
add a bit of C/C++ if some part of it was running too slowly. If there were existing C/C++ libraries then I'd use ctypes to interface with them. I don't think I ever want to start another large C++ app - been there, done that, got the (mental) scars to prove it ;-) All my humble opinio

Re: Why is recursion so slow?

2008-07-01 Thread Nick Craig-Wood
e here for a python memoize which makes the recursive algorithm run fast... http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/52201 -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Getting sorting order

2008-07-01 Thread Nick Craig-Wood
passing len(x) arguments to zip. So if x = [1,2,3,4] zip(*x) == zip(1,2,3,4) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Why is recursion so slow?

2008-07-02 Thread Nick Craig-Wood
Rich Harkins <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > [snip] > > By definition any function in a functional language will > > always produce the same result if given the same arguments, so you can > > memoize any function. > > > > Ah, s

Re: ctypes - unloading implicitly loaded dlls

2008-07-28 Thread Nick Craig-Wood
ll, but I haven't found any way of doing that. Can anyone offer > my some suggestions? Or, am I S.O.L.? You could try loading C explicitly with ctypes.LoadLibrary() before loading A, then you'll have a handle to unload it before you load B. I think I'd probably split the c

Re: ActiveState Code (the new Python Cookbook) has been launched

2008-07-28 Thread Nick Craig-Wood
n the old site! Mind telling us how it is implemented? I'm guessing python/django by the url and the fact that you have python stuff on your home pages but I could be wrong! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Interconvert a ctypes.Structure to/from a binary string?

2008-08-04 Thread Nick Craig-Wood
a.x 0 >>> memmove(addressof(a), packet, sizeof(a)) 3083811008L >>> a.x 258 I think the second of those methods is promoted by the ctypes documentation. I'm not sure about the lifetimes of the .contents in the first method! And the reverse >>>

Re: Problem with global variables

2008-08-09 Thread Nick Craig-Wood
--- class Test(object): def __init__(self): self.foo = [] def goo(self): self.foo.append(2) def moo(self): print self.foo test = Test() >>> from test2 import test >>> test.foo [] >>> test.goo() >>> test.foo [2] >>> test.moo() [2] >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: A Question about ctypes and a function f(void **)

2008-08-11 Thread Nick Craig-Wood
c_char_p(136692916) >>> s.value 'hello' >>> or use ctypes.memmove to copy the data out to somewhere else. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: export sites/pages to PDF

2008-08-12 Thread Nick Craig-Wood
to script that with python. See here for some more info on dcop :- http://www.ibm.com/developerworks/linux/library/l-dcop/ -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: bsddb3 thread problem

2008-04-01 Thread Nick Craig-Wood
I spent weeks trying to get it to behave when threading. I gave up in the end and changed to sqlite :-( At least if you make a mistake with sqlite and use the wrong handle in the wrong place when threading it gives you a very clear error. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://ww

Re: Homework help

2008-04-01 Thread Nick Craig-Wood
function howMany(item,lst) which accepts > an item and a lst of items and returns the number of times item occurs > in lst. For example, howMany(3,[1,2,3,2,3]) should return 2. Read section 4.1, 4.2 and 4.6 from here http://docs.python.org/tut/node6.html -- Nick Craig-Wood <[EMAIL

Re: bsddb3 thread problem

2008-04-02 Thread Nick Craig-Wood
ying to use it in thread Y which won't work". You can probably make bsddb work with threads, but I wasted too much time trying without success! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: is file open in system ? - other than lsof

2008-04-17 Thread Nick Craig-Wood
if not os.path.exists(link): continue open_files.setdefault(link, []).append(pid) for link in sorted(open_files.keys()): print "%s : %s" % (link, ", ".join(map(str, open_files[link]))) ---- You m

Re: I just killed GIL!!!

2008-04-18 Thread Nick Craig-Wood
dict unshareable, while immutable int and str objects can still be shared. Further, mutable objects that provide an explicit API for use between threads are also shareable. ---- -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: [Python 2.4/2.5] subprocess module is sorely deficient?

2008-04-22 Thread Nick Craig-Wood
if killpg: os.killpg(pgid, signal.SIGKILL) else: os.kill(pid, signal.SIGKILL) except OSError: return -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: [Python 2.4/2.5] subprocess module is sorely deficient?

2008-04-22 Thread Nick Craig-Wood
Mark Wooding <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Harishankar <[EMAIL PROTECTED]> wrote: > >> 1. Create non-blocking pipes which can be read in a separate thread > >> [...] > > > > You are correct o

Re: subprocess module is sorely deficient?

2008-04-23 Thread Nick Craig-Wood
uses pexpect fairly extensively to > interface with all sorts of other systems. We recently received > funding from Microsoft to do a native port of Sage (and all of its > components to Windows. Part of this will most likely be a port of > pexpect to Windows. Hooray! -- Nick Craig-Wood &

Re: function that accepts any amount of arguments?

2008-04-25 Thread Nick Craig-Wood
return v/len(x) > >> > > > > think you want total/len(x) in return statement > > > Yes indeed, how glad I am I wrote "untested". I clearly wasn't pair > programming when I wrote this post ;-) Posting to comp.lang.python is pair programming wit

Re: Little novice program written in Python

2008-04-25 Thread Nick Craig-Wood
learning the > language idioms). When you are up to speed in python I suggest you check out gmpy for number theory algorithms. Eg :- import gmpy p = 2 while 1: print p p = gmpy.next_prime(p) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.co

Re: Question regarding Queue object

2008-04-28 Thread Nick Craig-Wood
o be put in and all the threads will have to do is Queue.get() and be sure they've got a message they can deal with. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Receive data from socket stream

2008-04-28 Thread Nick Craig-Wood
new = client.recv(256) if not new: break data += new >From the man page for recv RETURN VALUE These calls return the number of bytes received, or -1 if an error occurred. The return value will be 0 when the peer has performed an orderly shutd

Re: Receive data from socket stream

2008-04-28 Thread Nick Craig-Wood
impossible to tell how much data has been sent. There should really be a recvall for symmetry, but I don't think it would get much use! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Regular Expression - Matching Multiples of 3 Characters exactly.

2008-04-28 Thread Nick Craig-Wood
7;, 'AUG', 'WWQWAWQWW', 'QWW', 'AGG') >>> > This way, I could scan for genes, remove the first letter, scan for > more genes, remove the first letter again, and scan for more genes. > This would hypothetically yield different genes, since the frame > would be shifted. Of you could just unconstrain the first match and it will do them all at once :- (AUG)((\w\w\w)*?)(AGG) You could run this with re.findall, but beware that this will only return non-overlapping matches which may not be what you want. I'm not sure re's are the best tool for the job, but they should give you a quick idea of what the answers might be. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Receive data from socket stream

2008-04-28 Thread Nick Craig-Wood
Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> writes: > > > What you are missing is that if the recv ever returns no bytes at all > > then the other end has closed the connection. So something like this > > is the corr

Re: Question regarding Queue object

2008-04-29 Thread Nick Craig-Wood
Terry <[EMAIL PROTECTED]> wrote: > On Apr 28, 5:30 pm, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > David <[EMAIL PROTECTED]> wrote: > > > Another idea would be to have multiple queues, one per thread or per > > > message type "group

Re: Receive data from socket stream

2008-04-29 Thread Nick Craig-Wood
lf.sock = None raise ServerDisconnectedException() self.rx_buf += rx return message Sorry I mis-understood your original post! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Receive data from socket stream

2008-04-29 Thread Nick Craig-Wood
Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> writes: > > >> Note that appending to a string is almost never a good idea, since it > >> can result in quadratic allocation. > > > > My aim was clear exposition

Re: Best way to store config or preferences in a multi-platform way.

2008-05-01 Thread Nick Craig-Wood
= os.path.join(self.home, "."+self.NAME) if not os.path.isdir(self.config_dir): os.makedirs(self.config_dir, mode=0700) self.config_file = os.path.join(self.config_dir, "config") -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: portable fork+exec/spawn

2008-05-02 Thread Nick Craig-Wood
eceive output, read exit code type jobs. For jobs which require interactivity ie send input, receive output, send input, receive output, ... it doesn't work well. There isn't a good cross platform solution for this yet. pyexpect works well under unix and is hopefully being ported to

Re: portable fork+exec/spawn

2008-05-03 Thread Nick Craig-Wood
ues since it's > event-driven. It took me a while but I found the documentation on this eventually http://twistedmatrix.com/documents/current/api/twisted.internet.interfaces.IReactorProcess.html Looks interesting - I'll have to try it next time I'm reaching for pexpect Thanks N

Re: Help with pyserial and sending binary data?

2008-05-03 Thread Nick Craig-Wood
immediately after plugging the port in. I do a lot of this sort of thing at work (not with cars though with satellite equipment) and it is always the first packet and the first response which is the hard part. After that it is usually plain sailing! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question - probably FAQ (but not exactly answered by regular FAQ)

2008-05-03 Thread Nick Craig-Wood
er idea ? Suggestions with > reasoning would be very helpful. Jython seems to be based off python 2.2 so you would be limited to 2.2 features in that case. No big deal in my opinion. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Feature suggestion: sum() ought to use a compensated summation algorithm

2008-05-03 Thread Nick Craig-Wood
y! > I thought that it would be very nice if the built-in sum() function used > this algorithm by default. Has this been brought up before? Would this > have any disadvantages (apart from a slight performance impact, but > Python is a high-level language anyway ...)? sum() gets used for any numerical types not just floats... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ISBN Barecode reader in Python?

2008-05-04 Thread Nick Craig-Wood
SDK doing the same? As it is a hobby > project, I don't like to spend money on the SDK. Pick yourself up a cue-cat barcode reader, eg from here or ebay http://www.librarything.com/cuecat These appear as a keyboard and "type" the barcode in to your program. Cheap and eff

Re: get the pid of a process with pexpect

2008-05-05 Thread Nick Craig-Wood
gt; Is there a way to get it using pexpect ? If I understand you correctly what you need to do is run "echo $$" on the remote shell then "exec tunnel_command". The $$ will print the pid and the exec will run tunnel_command without changing the pid. -- Nick Craig-Wood <[EMA

Re: Script using generators produces different results when invoked as a CGI

2008-05-05 Thread Nick Craig-Wood
file size... > Are you sure the script runs to completion? Output a message at the > end, to be sure. Check the ownership of all the files too. Remember that the web server (and hence your cgi) will likely run as nobody or www-data. You are unlikely to be logging in as one of those users. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Newbie question - probably FAQ (but not exactly answered by regular FAQ)

2008-05-06 Thread Nick Craig-Wood
vailable as a 3rd party module for 2.3 and 2.4. As is sqlite3. So in my opinion the real difference between the 2.2, 2.3, 2.4 and 2.5 are the built in modules. The actual language changes are very minor. If you write your code for 2.5 which is probably a good idea, you'll have no problem ba

Re: Numeric literal syntax (was: Py 2.6 changes)

2008-09-02 Thread Nick Craig-Wood
inimize programming errors, simple code mistakes > too. And perl also *ducks* -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: use str as variable name

2008-09-04 Thread Nick Craig-Wood
27; > a.__argname__= new_value Not quite sure what the above is supposed to achieve > rather than : > > if arg == 'height': >a.height = new_value > elif arg == 'width'; >a.width = new_value > > Can I do this with python ? How ? se

Re: creating an (inefficent) alternating regular expression from a list of options

2008-09-09 Thread Nick Craig-Wood
orting it to python but looking at the regular expressions made me feel weak at the knees ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Simple UDP server

2008-09-10 Thread Nick Craig-Wood
#x27;d use select and run asynchronously. http://docs.python.org/lib/module-select.html Actually if I really had to do this I'd use twisted. Right tool for the job! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: dict slice in python (translating perl to python)

2008-09-11 Thread Nick Craig-Wood
= mydict['two'] v3 = mydict['two'] Either is only a couple more characters to type. It is completely explicit and comprehensible to everyone, in comparison to v1,v2,v3 = [ mydict[k] for k in ['one','two','two']] # 52 chars v1,v2,v3 = [

Re: dict slice in python (translating perl to python)

2008-09-12 Thread Nick Craig-Wood
Steven D'Aprano <[EMAIL PROTECTED]> wrote: > On Thu, 11 Sep 2008 03:36:35 -0500, Nick Craig-Wood wrote: > > > As an ex-perl programmer and having used python for some years now, I'd > > type the explicit > > > > v1,v2,v3 = mydict['one

Re: Comparing float and decimal

2008-09-24 Thread Nick Craig-Wood
t the exact representations leak out anyway (which causes a lot of FAQs in this list), eg >>> 0.1 0.10001 IMHO We should put the exact conversions in for floats to Decimal and Fraction by default and add a new section to the FAQ! In that way people will see floats for what the

Re: How can I use a PyObject in C++?

2008-09-24 Thread Nick Craig-Wood
dn't read result from MyModule.SubModule.my_function"); goto out; } my_result = strdup(my_result); /* keep in our own memory */ out:; Py_XDECREF(result); Py_XDECREF(module); return my_result; } -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: PyRun_SimpleFile() crashes

2008-09-24 Thread Nick Craig-Wood
that you actually opened the file, ie file_1 != 0. This might be relevant http://effbot.org/pyfaq/pyrun-simplefile-crashes-on-windows-but-not-on-unix-why.htm -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Comparing float and decimal

2008-09-25 Thread Nick Craig-Wood
getcontext().prec += 1 finally: setcontext(oldcontext) print "float(0.1) is", floatToDecimal(0.1) -------- Prints this float(0.1) is 0.155511151231257827021181583404541015625 On my platform Python 2.5.2 (r252:60911, Aug 8 2008, 09:22:44), [GCC 4.3.1] on linux2 Linux 2.6.26-1-686 Intel(R) Core(TM)2 CPU T7200 -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Eggs, VirtualEnv, and Apt - best practices?

2008-09-25 Thread Nick Craig-Wood
to build an rpm and converting to a .deb. The app is then tested with "etch" or whatever. If easy_install could build debs that would be really helpful! > Suggestions on build/rollout tools (like zc.buildout, Paver, etc) would > also be appreciated. Use setup.py to build in

Re: Advice for a replacement for plone.

2008-09-30 Thread Nick Craig-Wood
jangoproject.com/en/dev/ref/contrib/flatpages/ A bit more of a learning curve but you'll definitely be in charge. Somebody used to Django could set up a flatpages site in 5 minutes probably! It will take you a couple of hours the first time though. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Tuple parameter unpacking in 3.x

2008-10-04 Thread Nick Craig-Wood
gt; >>> So just remove the parentheses and you'll be fine. I have to say I prefer named functions, but I haven't done much functional programming def f(ai, bi): return ai * bi ci.addCallback(f) def f(i, s): return field(i + 1), s map(f, enumerate(si))

Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-14 Thread Nick Craig-Wood
perate the two then the documention will lag the code.) PS I've used reST and perldoc. reST is easier to use for the easy things, but gets complicated for the hard things. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Tried Ruby (or, "what Python *really* needs" or "perldoc!")

2006-03-16 Thread Nick Craig-Wood
ython Modules (2.3) * Python2.3-ext: (python2.3-ext). Extending & Embedding Python 2.3 * Python2.3-lib: (python2.3-lib). Python 2.3 Library Reference * Python2.3-ref: (python2.3-ref). Python 2.3 Reference Manual * Python2.3-tut: (python2.3-tut). Python 2.3 Tutorial -- Nick

Re: Have you ever considered of mousing ambidextrously?

2006-03-19 Thread Nick Craig-Wood
l and index finger does right clicks. I'm now an ambidextrous mouse user. I still can't draw stuff with my left hand quite as well as my right, but I don't attempt that very often! I can't actually think of any possible way of getting this on topic, so I'll just mention

Re: To run a python script in all the machines from one server

2006-03-28 Thread Nick Craig-Wood
Enabled Size: Not Installed Error Status: OK -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Converting Time question

2006-03-28 Thread Nick Craig-Wood
amp() >>> datetime.datetime.utcfromtimestamp(1.090516451769E+15/1E6).isoformat()[-15:] '17:14:11.769000' -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: 1.090516455488E9 / 1000000.000 ???

2006-03-28 Thread Nick Craig-Wood
q/general/#why-are-floating-point-calculations-so-inaccurate Eg >>> a=1.090516455488E9 / 100 >>> print a 1090.51645549 >>> print repr(a) 1090.516455488 >>> If you want a given number of decimal places you can use a formatter, eg >>> print &quo

Re: Looking for a language/framework

2006-03-28 Thread Nick Craig-Wood
which we can't maintain any more into a django site, and we've been monstrously impressed! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Difference in Python and Ruby interactive shells

2006-04-10 Thread Nick Craig-Wood
I use which is easy and works just fine. I only type it once and then press up arrow to get it back! import workinprogress; reload(workinprogress); del(workinprogress); from workinprogress import * That gives you the module and all its globals rebound. -- Nick Craig-Wood <[EMAIL PROTECTE

Re: XML-RPC server via xinetd

2006-04-17 Thread Nick Craig-Wood
ooks as thought it almost, or maybe completely, does what you want, ie an XMLRPC subclass which reads from stdin and writes to stdout. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: ANN: GMPY 1.11rc1 is available

2009-11-30 Thread Nick Craig-Wood
whatever will they think of next ;-) Thanks for maintaining gmpy - it is an excellent bit of software! -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Error in linalg.inv ??

2009-06-06 Thread Nick Craig-Wood
b = reshape(a, [3,3]) >>> linalg.det(b) -9.5171266700777579e-16 >>> Which is zero but with a bit of rounding errors which I guess numpy doesn't notice. Double checking like this >>> a,b,c,d,e,f,g,h,i=range(1,10) >>> a*e*i - a*f*h - b*d*i + b*f*g + c*d*h -

Re: openhook

2009-06-06 Thread Nick Craig-Wood
Gaudha wrote: > Can anybody tell me what is meant by 'openhook' ? http://docs.python.org/library/fileinput.html?highlight=openhook Maybe ;-) -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: can it be shorter?

2009-06-06 Thread Nick Craig-Wood
> re.sub('/?$', '/', 'aaabbb') 'aaabbb/' >>> That solution is very perl-ish I'd say, IMHO if not url.endswith("/"): url += "/" is much more pythonic and immediately readable. In fact even someone who doesn't know python could understand what it does, unlike the regexp solution which requires a little bit of thought. -- Nick Craig-Wood -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

<    1   2   3   4   5   6   7   >