Re: concise code (beginner)

2007-09-10 Thread bambam
I have a number of news readers here, but all of them work better with top-posting, and in none of them is top posting a problem. What software are you using? Steve. Lawrence D'Oliveiro [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] In message [EMAIL PROTECTED], bambam wrote:

Re: concise code (beginner)

2007-09-10 Thread Francesco Guerrieri
On 9/10/07, bambam [EMAIL PROTECTED] wrote: I have a number of news readers here, but all of them work better with top-posting, and in none of them is top posting a problem. What software are you using? Steve. I use gmail and I can assure you that top posting is annoying. francesco --

Re: concise code (beginner)

2007-09-10 Thread Lawrence D'Oliveiro
A: Skid-marks in front of the hedgehog. Q: What's the difference between a dead hedgehog on the road, and a dead top-poster on the road? -- http://mail.python.org/mailman/listinfo/python-list

Re: concise code (beginner)

2007-09-10 Thread Marc 'BlackJack' Rintsch
On Mon, 10 Sep 2007 17:42:16 +1000, bambam wrote: Lawrence D'Oliveiro [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] In message [EMAIL PROTECTED], bambam wrote: Thank you, Don't top-post. I have a number of news readers here, but all of them work better with top-posting,

Re: concise code (beginner)

2007-09-10 Thread Paul Rudin
Marc 'BlackJack' Rintsch [EMAIL PROTECTED] writes: On Mon, 10 Sep 2007 17:42:16 +1000, bambam wrote: Lawrence D'Oliveiro [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] In message [EMAIL PROTECTED], bambam wrote: Thank you, Don't top-post. I have a number of news readers

Re: concise code (beginner)

2007-09-10 Thread Gabriel Genellina
Lawrence D'Oliveiro [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Why not just build a new list? E.g. newdevs = [] for dev in devs : ... if not removing_dev : newdevs.append(dev) #end if #end for devs = newdevs En Sun, 09 Sep 2007 22:58:54

Re: concise code (beginner)

2007-09-10 Thread Gabriel Genellina
Lawrence D'Oliveiro [EMAIL PROTECTED] wrote in message news:[EMAIL PROTECTED] Why not just build a new list? E.g. newdevs = [] for dev in devs : ... if not removing_dev : newdevs.append(dev) #end if #end for devs = newdevs En Sun, 09 Sep

Re: concise code (beginner)

2007-09-09 Thread bambam
Removing from a list while you iterate will had quadratic performance Anecdote: I was doing a route-finding program for a railway ticketing system. My replacement explained to my boss that it couldn't be done: the problem was one of that class of problems that has no good optimum solution.

Re: concise code (beginner)

2007-09-09 Thread bambam
I'm testing a series of scripts. The scripts are testing a series of hardware devices. The scripts are a sequence of device commands. The scripts have sequence numbers. I am adding exception handling to the to the 'inner platform' that executes sequences. I am doing this because testing of error

Re: concise code (beginner)

2007-09-09 Thread bambam
I can try that, but I'm not sure that it will work. The problem is that devList is just a pointer to a list owned by someone else. Making devList point to a new list won't work: I need to make the parent list different. I could do this by adding an extra level of indirection, but I think at the

Re: concise code (beginner)

2007-09-09 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], bambam wrote: Thank you, Don't top-post. -- http://mail.python.org/mailman/listinfo/python-list

Re: concise code (beginner)

2007-09-09 Thread Alex Martelli
bambam [EMAIL PROTECTED] wrote: O(n) to find the element you wish to remove and move over everything after it, Is that how lists are stored in cPython? It seems unlikely? So-called lists in Python are stored contiguously in memory (more like vectors in some other languages), so e.g. L[n]

Re: concise code (beginner)

2007-09-07 Thread Rhamphoryncus
On Sep 6, 1:56 pm, Karthik Gurusamy [EMAIL PROTECTED] wrote: That said, it may be a good future language enhancement to define a reasonable consistent behavior for an iterator over a changing collection. This occurs quite common when we walk a collection and usually delete the current item.

Re: concise code (beginner)

2007-09-07 Thread Michele Simionato
On Sep 6, 7:44 am, bambam [EMAIL PROTECTED] wrote: First, thank you. All of the suggestions match what we want to do much better than what we are doing. We have a script, written in python, which is doing testing. But the python script doesn't look anything like the test script, because the

Re: concise code (beginner)

2007-09-06 Thread Marc 'BlackJack' Rintsch
On Thu, 06 Sep 2007 15:44:57 +1000, bambam wrote: def script(self) def a0010(): global self; self.power_on([self.dev]); def a0020(): global self; self.dev.addLog([self.name, ' started']); def a0030(): global self; self.resetMinuteReg([self.dev]); def a0040(): global self;

Re: concise code (beginner)

2007-09-06 Thread Steven D'Aprano
On Thu, 06 Sep 2007 15:44:57 +1000, bambam wrote: First, thank you. All of the suggestions match what we want to do much better than what we are doing. We have a script, written in python, which is doing testing. But the python script doesn't look anything like the test script, because the

Re: concise code (beginner)

2007-09-06 Thread Karthik Gurusamy
On Sep 5, 1:37 pm, James Stroud [EMAIL PROTECTED] wrote: Karthik Gurusamy wrote: On Sep 5, 11:17 am, James Stroud [EMAIL PROTECTED] wrote: for i in xrange(number_of_reads): for dev in devs: try: _reader = getattr(dev, 'read%d' % i) _reader() except

Re: concise code (beginner)

2007-09-06 Thread bambam
Hi Steven. Looking at your code, why are you naming the value __all__? It looks like a built-in variable? Unless there is an automatic way to correctly get the function list, I will probably be better off giving the lines sequence numbers, and generating the function list from that. Steve.

Re: concise code (beginner)

2007-09-06 Thread Steven D'Aprano
On Fri, 07 Sep 2007 12:03:26 +1000, bambam wrote: Hi Steven. Looking at your code, why are you naming the value __all__? It looks like a built-in variable? When you say: from module import * Python looks in the module for a list of names called __all__, and imports only the names in that

Re: concise code (beginner)

2007-09-06 Thread Lawrence D'Oliveiro
In message [EMAIL PROTECTED], bambam wrote: The devices are in a list, and are removed by using pop(i). This messes up the loop iteration, so it is actually done by setting a flag on each device in the exception handler, with ANOTHER loop after each write/read/calculate sequence. Why not

concise code (beginner)

2007-09-05 Thread bambam
I have about 30 pages (10 * 3 pages each) of code like this (following). Can anyone suggest a more compact way to code the exception handling? If there is an exception, I need to continue the loop, and continue the list. Steve. --- for dev in devs try:

Re: concise code (beginner)

2007-09-05 Thread Diez B. Roggisch
bambam wrote: I have about 30 pages (10 * 3 pages each) of code like this (following). Can anyone suggest a more compact way to code the exception handling? If there is an exception, I need to continue the loop, and continue the list. Steve. --- for dev

Re: concise code (beginner)

2007-09-05 Thread Wesley Brooks
Try adding all the functions into a list such as; funcList = [dev.read1, dev.read2, dev.read3] for func in funcList: for dev in devs: try: func() except: print exception remove dev from devs Wes. On 05/09/07, bambam [EMAIL PROTECTED] wrote: I

Re: concise code (beginner)

2007-09-05 Thread Daniel Larsson
def process_devs(devs, fun): for dev in devs: try: fun(dev) except: print exception remove dev from devs return devs process_devs(devs, lambda d: d.read1()) process_devs(devs, lambda d: d.read2()) ... On 9/5/07, bambam [EMAIL

Re: concise code (beginner)

2007-09-05 Thread Francesco Guerrieri
On 9/5/07, bambam [EMAIL PROTECTED] wrote: I have about 30 pages (10 * 3 pages each) of code like this (following). Can anyone suggest a more compact way to code the exception handling? If there is an exception, I need to continue the loop, and continue the list. Steve.

Re: concise code (beginner)

2007-09-05 Thread Wesley Brooks
Sorry, just seen a mistake in my code, however Diez beat me to what I was actually thinking! Wes On 05/09/07, Wesley Brooks [EMAIL PROTECTED] wrote: Try adding all the functions into a list such as; funcList = [dev.read1, dev.read2, dev.read3] for func in funcList: for dev in devs:

Re: concise code (beginner)

2007-09-05 Thread Bruno Desthuilliers
bambam a écrit : I have about 30 pages (10 * 3 pages each) of code like this (following). Can anyone suggest a more compact way to code the exception handling? If there is an exception, I need to continue the loop, and continue the list. Steve. --- for

Re: concise code (beginner)

2007-09-05 Thread James Stroud
bambam wrote: I have about 30 pages (10 * 3 pages each) of code like this (following). Can anyone suggest a more compact way to code the exception handling? If there is an exception, I need to continue the loop, and continue the list. Steve. --- for dev

Re: concise code (beginner)

2007-09-05 Thread Karthik Gurusamy
On Sep 5, 11:17 am, James Stroud [EMAIL PROTECTED] wrote: bambam wrote: I have about 30 pages (10 * 3 pages each) of code like this (following). Can anyone suggest a more compact way to code the exception handling? If there is an exception, I need to continue the loop, and continue the

Re: concise code (beginner)

2007-09-05 Thread Daniel Larsson
On 9/5/07, Karthik Gurusamy [EMAIL PROTECTED] wrote: On Sep 5, 11:17 am, James Stroud [EMAIL PROTECTED] wrote: bambam wrote: I have about 30 pages (10 * 3 pages each) of code like this (following). Can anyone suggest a more compact way to code the exception handling? If there is an

Re: concise code (beginner)

2007-09-05 Thread James Stroud
Karthik Gurusamy wrote: On Sep 5, 11:17 am, James Stroud [EMAIL PROTECTED] wrote: for i in xrange(number_of_reads): for dev in devs: try: _reader = getattr(dev, 'read%d' % i) _reader() except Exception, e: print e devs.remove(dev) I see in

Re: concise code (beginner)

2007-09-05 Thread Francesco Guerrieri
On 9/5/07, James Stroud [EMAIL PROTECTED] wrote: Another way is to make a copy of devs, if devs is short, which makes my When I process something of that genre (e.g. files) I prefer not to lose trace of what's happened by removing the bad items. Instead I prefer to flag or otherwise to

Re: concise code (beginner)

2007-09-05 Thread bambam
First, thank you. All of the suggestions match what we want to do much better than what we are doing. We have a script, written in python, which is doing testing. But the python script doesn't look anything like the test script, because the python script is written in python, and the test script