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.

Adding extra modules to a Pyinstaller build

2007-10-08 Thread Craig
project? Regards, Craig -- 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: How to create a file on users XP desktop

2007-10-07 Thread Craig Howard
On Oct 6, 2007, at 11:31 PM, goldtech wrote: > Can anyone link me or explain the following: > > I open a file in a python script. I want the new file's location to be > on the user's desktop in a Windows XP environment. fileHandle = open > (., 'w' ) what I guess I'm looking for is an enviro

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

2007-10-05 Thread Craig Howard
is sent to the plant operator's pager. Because of the nature of the alarm system, extensive field testing was out of the question. Unit testing was the only way to ensure it worked without disrupting the plant operation. Craig -- 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: 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: 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: 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: 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: [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: Unable to read large files from zip

2007-08-29 Thread Nick Craig-Wood
a go at fixing it! Try editing zipfile.py and getting it to print out some debug info and see if you can fix the problem. When you have done submit the patch to the python bug tracker and you'll get that nice glow from helping others! Remember python is open source and is made by *us* for *us

Re: Haskell like (c:cs) syntax

2007-08-29 Thread Nick Craig-Wood
Erik Jones <[EMAIL PROTECTED]> wrote: > front, last = l[:len(l) - 1], l[len(l) - 1] Normally written as front, last = l[:-1], l[-1] -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: tempfile.mkstemp and os.fdopen

2007-08-29 Thread Nick Craig-Wood
gt; > You can do this under Linux as follows: > > os.readlink("/proc/%d/fd/%d" % (os.getpid(), fileno)) A good idea! You can write this slightly more succinctly as os.readlink("/proc/self/fd/%d" % fileno) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: tempfile.mkstemp and os.fdopen

2007-08-28 Thread Nick Craig-Wood
f doing things. It can't race under unix at least (dunno about windows) unless your dir is on NFS. If you want more security then make sure dir isn't publically writeable. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python's Suitability?

2007-08-28 Thread Nick Craig-Wood
t; Python users. TIA Go for it! Python is such an easy language to write stuff in (escpecially compared to C++) that you'll have the prototype done very quickly and you can evaluate the rest of your concerns with working code! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Error with long running web spider

2007-08-22 Thread Nick Craig-Wood
programs. Any ideas? If you were running under unix I'd suggest you "strace" the process to see what it is doing. There are windwows strace programs (which I've never tried) too! You'll probably find it is wedged in TCP socket code. -- Nick Craig-Wood <[EMAIL

Re: File Read Cache - How to purge?

2007-08-22 Thread Nick Craig-Wood
Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> writes: > > > If you are running linux > 2.6.18 then you can use > > /proc/sys/vm/drop_caches for exactly that purpose. > > > > http://www.linuxinsight.com/proc_sys_vm_dr

Re: File Read Cache - How to purge?

2007-08-21 Thread Nick Craig-Wood
eno() 3 >>> libc.readahead(f.fileno(), 0, 0x100) 0 >>> (That example could do with more ctypes magic to set the types and the return type of readahead...) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: File Read Cache - How to purge?

2007-08-21 Thread Nick Craig-Wood
total used free sharedbuffers cached Mem: 1036396 587296 449100 0392 91284 # echo 3 > /proc/sys/vm/drop_caches # free total used free sharedbuffers cached Mem: 1036396 588228 448168

Re: How to decompress .Z file?

2007-08-20 Thread Nick Craig-Wood
cording to python library reference, .Z file might not be > supported by python, yet. Unfortunately the python gzip library doesn't read .Z files. I'd pipe the data to zcat using subprocess to decompress from python. I haven't used a .Z files for many many years - where are you

Re: Python equivalent of Perl's $/

2007-08-20 Thread Nick Craig-Wood
thout wishing to start a flame war, is there a way to do this in Python? """ for para in re.split(r"\.\n", input_data): print "para = %r" % para -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python and Tkinter Programming--Expensive!

2007-08-18 Thread Nick Craig-Wood
27;ve got the 2nd edition. Lutz concentrates on TK programming using classes, making re-usable components which I found really helpful compared to the ad-hoc way I'd seen TK presented previously. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-18 Thread Nick Craig-Wood
mulate a perl hash then you would want this which does the above but recursively. from collections import defaultdict class hash(defaultdict): def __init__(self): defaultdict.__init__(self, hash) D=hash() D[1][2][3][4]=5 D[1][4][5]=6 print D -- Nick Craig-Wood <[EMA

Re: How to say $a=$b->{"A"} ||={} in Python?

2007-08-18 Thread Nick Craig-Wood
a very small amount of time creating a dict you don't use. $ python -m timeit '{}' 100 loops, best of 3: 0.247 usec per loop On my machine 250 ns gets you a new dict... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: The Future of Python Threading

2007-08-11 Thread Nick Craig-Wood
Bjoern Schliessmann <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > [GIL] > > That is certainly true. However the point being is that running > > on 2 CPUs at once at 95% efficiency is much better than running on > > only 1 at 99%... > > How do you de

Re: The Future of Python Threading

2007-08-10 Thread Nick Craig-Wood
he moment and a python-mt build which has the GIL broken down into a lock on each object. python-mt would certainly be slower for non threaded tasks, but it would certainly be quicker for threaded tasks on multiple CPU computers. The user could then choose which python to run. This would of

Re: High performance binary data

2007-08-10 Thread Nick Craig-Wood
g with binary data. I am looking for a any > one with experience or ideas on the subject. Pointers any one? Check out construct: http://construct.wikispaces.com/ -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: wxPython and threads

2007-07-19 Thread Nick Craig-Wood
Josiah Carlson <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > I'd dispute that. If you are communicating between threads use a > > Queue and you will save yourself thread heartache. Queue has a non > > blocking read interface Queue.get_nowait(). >

Re: wxPython and threads

2007-07-19 Thread Nick Craig-Wood
en > there is actual contention for a resource and you want to block when a > resource is not available). I'd dispute that. If you are communicating between threads use a Queue and you will save yourself thread heartache. Queue has a non blocking read interface Queue.get_nowait().

Re: Interprocess communication woes

2007-07-19 Thread Nick Craig-Wood
e via subprocess) then it will buffer stuff as you've seen. So you can a) modify the c++ prog to add fflush() in or use setvbuf() b) use the pexpect module - http://pexpect.sourceforge.net/ c) use the pty module (unix only) The pexpect module will connect to the subprogram with pseudo-ttys, fool

Re: Pickled objects over the network

2007-07-18 Thread Nick Craig-Wood
he cost of a bit of speed. http://pyro.sourceforge.net/manual/9-security.html#pickle -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Single-stepping through a python script

2007-07-17 Thread Craig Howard
>>Craig Howard schrieb: >> Hello All: >> >> Is is possible to compile a code object and single-step through its >> execution? >import pdb; pdb.set_trace() > >Look up the pdb module documentation. > >Diez Sorry, I didn't give enough deta

Re: Embedding/Extending Python in/with C++: non-static members?

2007-07-17 Thread Nick Craig-Wood
o poke object code onto the heap which implements the method call to that particular instance. Looking at this page might give you some ideas http://gcc.gnu.org/onlinedocs/gccint/Trampolines.html This probably isn't a good approach in reality though as it is very architecture / compiler depend

Single-stepping through a python script

2007-07-17 Thread Craig Howard
Hello All: Is is possible to compile a code object and single-step through its execution? Craig -- http://mail.python.org/mailman/listinfo/python-list

Re: os.wait() losing child?

2007-07-12 Thread Nick Craig-Wood
Hrvoje Niksic <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> writes: > > >> I think your polling way works; it seems there no other way around this > >> problem other than polling or extending Popen class. > > > > I thi

Re: os.wait() losing child?

2007-07-12 Thread Nick Craig-Wood
Jason Zheng <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood wrote: > > The problem you are having is you are letting Popen do half the job > > and doing the other half yourself. > > Except that I never wanted Popen to do any thread management for me to > begin wi

Re: 2**2**2**2**2 wrong? Bug?

2007-07-12 Thread Nick Craig-Wood
same as 2**(3*2) or 2**6=64. > > Just for curiosity: This helps to find the answer to the problem "Which is > the largest number that can be written with only 3 digits?" > Some people stop at 999, others try 99**9 and 9**99, and the winner is > 9**9**9, or: Actually

Re: storing pickles in sql data base

2007-07-11 Thread Nick Craig-Wood
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> b = dumps(a).encode("zip").encode("base64").strip() >>> b 'eJzTyCkw5PI04Er0NARiIyA2BmITIDYFYjMgNgdiCyC25ErUAwD5DQqD' >>> loads(b.decode("base64").decode("zip")) [0, 1, 2, 3, 4, 5, 6, 7

Re: bool behavior in Python 3000?

2007-07-11 Thread Nick Craig-Wood
False = False If you want to do algebra with bools in python then use the logical operators (and or not) and not the arithmetical operators. Eg >>> False or not True False -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: os.wait() losing child?

2007-07-11 Thread Nick Craig-Wood
reduce(lambda x,y: x and (y>=10), counts): break continue print "Child Process %d terminated, restarting" % i processes[i] = Popen('sleep 1', shell=True, cwd='/home', stdout=file(os.devnull,'w')) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: subprocess popen trouble

2007-07-10 Thread Nick Craig-Wood
use pexpect which will connect to your prog with pseudo-ttys I recommend c) - subprocess isn't really very good at interactive conversations between the main process and the subprocess - buffering will cause you problems. You may in this simple case get it to work with a) or b) though! -- Nick C

Re: Should I use Python for these programs?

2007-07-10 Thread Nick Craig-Wood
OK, but a bit clunky. it does have the advantage that it is built into the language though. > Do you think Python is the right language for these projects? Yes! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: "Empty" text

2007-07-10 Thread Nick Craig-Wood
Miles <[EMAIL PROTECTED]> wrote: > On Jul 9, 4:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Marc 'BlackJack' Rintsch <[EMAIL PROTECTED]> wrote: > > > On Sun, 08 Jul 2007 22:23:20 +0200, Jan Danielsson wrote: > > > >Fire

Re: trouble controlling vim with subprocess on windows machine

2007-07-09 Thread Nick Craig-Wood
s one way communication - it isn't good at conversations. I'd suggest pexpect but it doesn't work on windows. You appear to be doing stuff with csound. There are several python modules out there which interface with csound - did you investigate those? -- Nick Craig-Wood <

Re: "Empty" text

2007-07-09 Thread Nick Craig-Wood
hinks it's HTML. I suspect the former - we noticed exactly the same thing (can't remember which tags we were having problems with), using the declaration :- http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";> I haven't tested this again recently though. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: How to Machine A python script execute Machine B python script?

2007-07-09 Thread Nick Craig-Wood
d normally. With only a few lines of extra code, Pyro takes care of the network communication between your objects once you split them over different machines on the network. All the gory socket programming details are taken care of, you just call a method on a remote object as if it were a l

Re: Callback scoping

2007-07-05 Thread Nick Craig-Wood
behavior I want? (If you haven't guessed, I want a list of (no > parameter) functions, each of which returns its index in the list.) This is the traditional way :- >>> x = [ lambda ind=ind: ind for ind in range(10) ] >>> x[0]() 0 >>> x[2]() 2 >

Re: what is wrong with that r"\"

2007-07-05 Thread Nick Craig-Wood
7;' '\'"' >>> Neil is correct in saying that his example works for regexp matching though, as the regexp matcher understands \" as being the same as ". So r"" strings work well as Regexp-strings but not so well as Raw-strings IMHO. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: what is wrong with that r"\"

2007-07-04 Thread Nick Craig-Wood
t; SyntaxError: EOL while scanning single-quoted string > > >>> r"\ " > > '\\ ' > > One slash escapes the following character, so the proper way of > writing it is either > > r"\\" or r"\"" I don't think so.

Re: what is wrong with that r"\"

2007-07-04 Thread Nick Craig-Wood
te character). b) That is a logical consequence of a) > Note also that a single backslash followed by a newline is > interpreted as those two characters as part of the string, not > as a line continuation. As I'd expect. If we removed a) then we could remove b) also a

Re: How to close a program I execute with subprocess.Popen?

2007-07-01 Thread Nick Craig-Wood
mmands in os, ie os.setpgid and os.getpgid. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: 16bit hash

2007-06-27 Thread Nick Craig-Wood
algorithms if you want something for making a hash table. They make very bad cryptographic hash generators since they are linear and thus easily forgeable. That said you aren't going to be doing any serious crypto with only 16 bits. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

import data.py using massive amounts of memory

2007-06-27 Thread Nick Craig-Wood
memory_usage import memory from cPickle import load before = memory() z = load(open("z.bin", "rb")) after = memory() print "Memory used to unpickle is %s kB" % (after-before) print "Total size of repr(z) is ",len(repr(z)) -- 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

Re: Chroot Jail Not Secure for Sandboxing Python?

2007-06-25 Thread Nick Craig-Wood
programs and system servers to the minimum amount of privilege they require to do their jobs. When confined in this way, the ability of these user programs and system daemons to cause harm when compromised (via buffer overflows or misconfigurations, for example) is reduced or eliminated. --

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: 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: 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: 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: 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
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
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: 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: 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-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: 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: 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: 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: 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: 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: Module listing in order.

2007-05-28 Thread Nick Craig-Wood
j in locals().values(): try: if issubclass(obj, Definition): objects.append(obj) except TypeError: pass objects_sorted = sorted(objects, key=lambda x: x._class_sequence) print objects # Gives something like # [, , , , , ] print objects_sorted # Gives # [, , , , , ] -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: zipfile stupidly broken

2007-05-19 Thread Nick Craig-Wood
Martin Maney <[EMAIL PROTECTED]> wrote: > Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > You don't need to do that, you can just "monkey patch" the _EndRecData > > function. > > For a quick & dirty test, sure. If I were certain I'd onl

Re: zipfile stupidly broken

2007-05-18 Thread Nick Craig-Wood
) the leading candidate is to copy and paste the whole frigging > zipfile module so I can patch it, but that's even uglier than it is > stupid. "This battery is pining for the fjords!" You don't need to do that, you can just "monkey patch" the _EndRecData

Re: How to convert a number to binary?

2007-05-18 Thread Nick Craig-Wood
mbda x: (dec2bin(x/2) + str(x%2)) if x else '' > > This is awesome. Exactly what I was looking for. Works for other > bases too. Just don't pass it a negative number ;-) -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: A bug in cPickle?

2007-05-17 Thread Nick Craig-Wood
001799'\np1\n." >>> pickle.dumps('1001799') "S'1001799'\np0\n." >>> pickle.loads(pickle.dumps('1001799')) '1001799' >>> pickle.loads(cPickle.dumps('1001799')) '1001799' >>> cPickle.loads(pickle.dumps('1001799')) '1001799' >>> cPickle.loads(cPickle.dumps('1001799')) '1001799' >>> -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Trying to choose between python and java

2007-05-15 Thread Nick Craig-Wood
e else have any useful comments about python vs java > without starting a flame war. You'll be a lot more productive writing python code in my experience so if development time is important to you, then go with python. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Subprocess with and without shell

2007-05-15 Thread Nick Craig-Wood
;, pipe.stdout.read() ---zz.py #!/usr/bin/python import sys print >>sys.stdout, "Stdout" print >>sys.stderr, "Stderr" ---- Produces $ ./z.py Without shell

Re: PEP 3131: Supporting Non-ASCII Identifiers

2007-05-14 Thread Nick Craig-Wood
nity. c) the python keywords are in ASCII/English. I hope you weren't thinking of changing them? ... In summary, I'm not particularly keen on the idea; though it might be all right in private. Unicode identifiers are allowed in java though, so maybe I'm worrying too much ;-)

Re: Asyncore Help?

2007-05-14 Thread Nick Craig-Wood
ral things with twisted. It takes a bit of getting your head round but you'll be impressed with the speed. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: High resolution sleep (Linux)

2007-05-11 Thread Nick Craig-Wood
Bart <[EMAIL PROTECTED]> wrote: > What about C module with usleep,nanosleep? Unlikely to help! It is an linux OS limit that the minimum sleep time is 1/HZ. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Python Binding

2007-05-06 Thread Nick Craig-Wood
ave a shared library (.so or .dll). You'll end up writing python code rather than C code which you'll enjoy! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: High resolution sleep (Linux)

2007-05-05 Thread Nick Craig-Wood
actual = 1.02E-04 expected = 1.00E-05 actual = 1.19E-05 expected = 1.00E-06 actual = 2.66E-06 on my 250 HZ machine You could then do run-time calibration to work out the overhead of the function on any given machine to make it more accurate. -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: My Python annoyances

2007-05-04 Thread Nick Craig-Wood
lding extensions. Using the windows python build in a windows command windows always works though (with mingw as the compiler). -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Want to build a binary header block

2007-05-02 Thread Nick Craig-Wood
00\x02\x00\x00\x03\x00\x00\x00\x00\x04\x00\x00' >>> You might also want to consider Construct http://construct.wikispaces.com/ >From the web page: Construct is a python library for parsing and building of data structures (binary or textual). It is based on the concept of d

Re: trinary operator - if then else

2007-04-25 Thread Nick Craig-Wood
why it "usually" > works (and often enough not). This for example won't work: > > >>> False or '' and 0 > '' You can use this if you want it to be bullet proof (a and [b] or [c])[0] Not exactly elegant though! -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Convert a string to a list

2007-04-24 Thread Nick Craig-Wood
x27;, '..', 'cdslib_cleanup.py', 'cadence.py', 'cdsinit_cdsenv_cleanup.py') >>> b='("." ("cadence.py" "foo_cleanup.py") "cdslib_cleanup.py" "cadence.py" >>> "cdsinit_cdsenv_cleanup.py")' >>> eval(b.replace('" "', '", "').replace('" (', '", (').replace(') "', '), "')) ('.', ('cadence.py', 'foo_cleanup.py'), 'cdslib_cleanup.py', 'cadence.py', 'cdsinit_cdsenv_cleanup.py') >>> It made tuples rather than lists but I expect that won't matter. Someone normally chimes in with pyparsing at this point... -- Nick Craig-Wood <[EMAIL PROTECTED]> -- http://www.craig-wood.com/nick -- http://mail.python.org/mailman/listinfo/python-list

Re: Binary file output using python

2007-04-19 Thread Nick Craig-Wood
gt;> import os >>> os.system("ls -l z") -rw-r--r-- 1 ncw ncw 45010006 Apr 19 18:43 z 0 >>> Indicating each float took 9 bytes to store, which is 1 byte more than a 64 bit float would normally take. The pickle dump / load each took about 2 seconds. -- 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: 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: 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: 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-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-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-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-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-27 Thread Nick Craig-Wood
Klaas <[EMAIL PROTECTED]> wrote: > On Mar 26, 3:30 am, Nick Craig-Wood <[EMAIL PROTECTED]> wrote: > > Did anyone write a contextmanager implementing a timeout for > > python2.5? > > > > I'd love to be able to write something li

<    1   2   3   4   5   6   7   8   9   >