Re: Merging overlapping spans/ranges

2005-05-10 Thread Mike Rovner
Max M wrote: I am writing a find-free-time function for a calendar. There are a lot of time spans with start end times, some overlapping, some not. To find the free time spans, I first need to convert the events into a list of non overlapping time spans meta-spans. Almost linear method

Re: Python Challenge ahead [NEW] for riddle lovers

2005-04-30 Thread Mike Rovner
Tim Peters wrote: [Mike Rovner] 3 IS wrong because if you use any not BIG letter after bodyguard on both sides, you get extra 'eCQQmSXK\n' which slow me down for 5 minutes. Get rid of the newlines first. On level 7, I'm not sure whether there's something more to do, or whether I'm looking

Re: How to track down all required shared libraries?

2005-04-30 Thread Mike Rovner
sdhyok wrote: Recently, I installed many shared libraries to run a program written in Python. Now, I am in the situation to run the same program but on several different machines with the same Linux OS. To avoid the reinstallation, I like to pack up all shared libraries into a directory. Is there

Re: Python Challenge ahead [NEW] for riddle lovers

2005-04-29 Thread Mike Rovner
David Murmann wrote: Shane Hathaway wrote: That was pretty fun. Good for a Friday. Too bad it comes to an abrupt temporary end. Shane P.S. I hope I didn't hammer your server on step 3. I was missing the mark. :-) Interestingly step 3 is actually wrong... there is an additional solution, which

Re: How to pass a arg of object to python's script in a c++ program?

2005-04-26 Thread Mike Rovner
Couple notes: - boost.python issues better discuss in comp.lang.python.c++ group; - debug your extension from python first, then embed it - don't call PyFinalize() zghelp wrote: but the exception occur when run to print t.greet() How can I solve it? Providing exception text will be helpful. Mike

Re: Python sleep doesn't work right in a loop?

2005-04-06 Thread Mike Rovner
[EMAIL PROTECTED] wrote: ... SHOULD toggle On and Off four times with one-second pauses. When I run this, the loop pauses the full eight seconds then prints the Ons and Offs all at once. What's up with that? Run your script as: python -u script.py for unbuffered output. --

Re: Python sleep doesn't work right in a loop?

2005-04-06 Thread Mike Rovner
[EMAIL PROTECTED] wrote: Nope. Does't work. Running Python 2.3.4 on Debian, Linux kernel 2.6. This is actually test code for a larger project... # flash the selected wx.TextControl for flasher in range(4): self.textField.SetBackgroundColour(255, 0, 0) self.textField.Update()

Re: os.path query functions behavior incorrect?

2005-04-05 Thread Mike Rovner
Beman Dawes wrote: So are these os.path functions specified and implemented incorrectly? Should they instead throw exceptions for the above examples? Works for me. (Win XP SP2, Py 2.4, only have c and d drives) os.path.exists('d:\\') True os.path.exists('e:\\') False os.path.exists('a:\\')

Re: truncating a file from the top down

2005-03-29 Thread Mike Rovner
rbt wrote: if os.stat says the file is too big: read the file trim = only keep the last 2008 bytes (This is where I get stuck) write trim back out to the original file Would someone demonstrate the *best* most efficient way of doing this? if os.stat says the_file is too big: fh =

Re: truncating a file from the top down

2005-03-29 Thread Mike Rovner
Right. Thanks for the correction. Fredrik Lundh wrote: Mike Rovner wrote: if os.stat says the_file is too big: fh = open(the_file, 'rb') fh.seek(2008, 2) should be fh.seek(-2008, 2) right? data = fh.read() fh.close() assert len(data)==2008 # you may want some error processing here fh

Re: String Splitter Brain Teaser

2005-03-27 Thread Mike Rovner
Jp Calderone wrote: On Sun, 27 Mar 2005 14:39:06 -0800, James Stroud [EMAIL PROTECTED] wrote: ATT/GATA/G gets split to [['A'], ['T'], ['T', 'G'], ['A'], ['T'], ['A', 'G']] I have written a very ugly function to do this (listed below for the curious), but intuitively I think this should only take

Re: tree data structure

2005-03-25 Thread Mike Rovner
vivek khurana wrote: i am a new member on this list. I have to implement tree data structure using python. How it can be done in python. Is there an existing data structure which can be used as tree? I have searched archives and manuals but no luck. You can start with Guido's essay

Re: comparison puzzle? bug?

2005-03-22 Thread Mike Rovner
Charles Hixson wrote: I hesitate to call this a bug, as at my level of expertise that seems ... unlikely. But I can't think of any other explanation: Call it 'typo' ;) printitem[0] lvl = %d %d = %(item[0], lvl), bool(item[0] == lvl) use bool(item[0] lvl) HTH, Mike --

multi-threaded list update

2005-03-22 Thread Mike Rovner
Hello, Please advise on multi-threaded list *append*: import time, random, thread aList = [] def main(): for i in range(10): thread.start_new_thread(updater, (i,)) time.sleep(30) print aList def updater(n): global aList time.sleep( random.randint(1,n+1) ) aList.append(n) if

Re: Read from the last line of a file?

2005-03-22 Thread Mike Rovner
Anthony Liu wrote: I am wondering if it is possible to start reading from the last line of file, and then the last but one up to the first line. If you can afford to keep the whole file in memory, than: lines = open(..).readlines() print lines[::-1] Otherwise you can use seek() to random-access

Re: multi-threaded list update

2005-03-22 Thread Mike Rovner
Peter Hansen wrote: (But if you can accept those drawbacks, keep doing what you're doing. Also consider searching the archives for discussions involving the dis module (google for dis.dis maybe?) and see how to learn for yourself what is atomic and what's not.) Thanks, Peter. I googled groups on

Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Mike Rovner
Paul Rubin wrote: If the compiler can do some type inference, it can optimize out those multiple calls pretty straightforwardly. It can be tipped like that: di = dict(int) di.setdefault(0) di[key] += 1 dl = dict(list) dl.setdefault([]) dl.append(word) dl.extend(mylist) But the point is that if

Re: Pre-PEP: Dictionary accumulator methods

2005-03-20 Thread Mike Rovner
Reinhold Birkenfeld wrote: I don't quite understand that. Which dict item are you extending? Don't you need something like dl[key].append(word) Rigth. It was just a typo on my part. Thanks for fixing. Mike -- http://mail.python.org/mailman/listinfo/python-list

Re: Pre-PEP: Dictionary accumulator methods

2005-03-18 Thread Mike Rovner
Ivan Van Laningham wrote: Hi All-- Maybe I'm not getting it, but I'd think a better name for count would be add. As in d.add(key) d.add(key,-1) d.add(key,399) etc. IMHO inc (for increment) is better. d.inc(key) add can be read as add key to d Mike --