Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Cameron Simpson
On 20Mar2015 19:20, Martin A. Brown wrote: [...] Short version: (Apologies, Jack Nicholson, in demonic form or otherwise): * You can't 'handle': STOP, CONT, KILL, SEGV, BUS. You can handle SEGV and BUS. Though probably not meaningfully in Python, haven't tried; if they fire in Python someth

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Martin A. Brown
Hi, This is mostly a distant footnote to Doug Basberg's original question, which I believe is largely answered at this point. Albert-Jan Roskum, Alan Gauld and Steven D'Aprano were asking about signals and how they are handled (in Un*xen). I am trying to address that. Yeah, I know you c

Re: [Tutor] Fastest find in 2 2D lists with else statement

2015-03-20 Thread Steven D'Aprano
On Fri, Mar 20, 2015 at 08:22:03AM -0400, Kale Good wrote: > Hello all, > I'm new to python and a bit of a weekend-warrior programmer (guitar > teacher by trade), so there are plenty of computer sciencey concepts > that I haven't grasped yet, and I think I'm bumping up against those now. > > Rea

Re: [Tutor] Reversi Game Logic

2015-03-20 Thread Dave Angel
On 03/20/2015 06:20 PM, niyanax...@gmail.com wrote: Thank you Danny Yoo for replying. I figured out what to do for the isLegalMove but I ran into another problem. I now get a traceback error every chip is black. This is the traceback: Traceback (most recent call last): File "C:\Python34\l

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Steven D'Aprano
On Fri, Mar 20, 2015 at 08:35:34PM +, Alan Gauld wrote: > Yeah, I know you can catch a signal and add your own handler, but I > meant what is the default Python suspend behaviour? Does it execute any > outstanding exception blocks? What about finally blocks? Or, if about to > exit a context

Re: [Tutor] Reversi Game Logic

2015-03-20 Thread niyanaxx95
Thank you Danny Yoo for replying. I figured out what to do for the isLegalMove but I ran into another problem. I now get a traceback error every chip is black. This is the traceback: Traceback (most recent call last): File "C:\Python34\lib\tkinter\__init__.py", line 1487, in __call__ re

Re: [Tutor] Reversi Game Logic

2015-03-20 Thread Dave Angel
On 03/20/2015 01:28 PM, niyanax...@gmail.com wrote: You have more than one copy of some lines of previous messages, and more than one version of code in the message. So I have to guess which one you intend to be current. Thank you Mark for replying. I fixed the note you provided on the

Re: [Tutor] Fastest find in 2 2D lists with else statement

2015-03-20 Thread Mark Lawrence
On 20/03/2015 12:22, Kale Good wrote: Hello all, I'm new to python and a bit of a weekend-warrior programmer (guitar teacher by trade), so there are plenty of computer sciencey concepts that I haven't grasped yet, and I think I'm bumping up against those now. Welcome to the club :) Read from

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Alan Gauld
On 20/03/15 20:04, Albert-Jan Roskam wrote: (BTW Does anyone know what the interpreter does when suspending - Ctrl-Z in Unix land?) No experience with it, but I would first check the 'signal' module Yeah, I know you can catch a signal and add your own handler, but I meant what is the defaul

Re: [Tutor] Reversi Game Logic

2015-03-20 Thread niyanaxx95
I am very new to Comp Science and am still learning. I have attached the programs needed for testing to show that I am testing my code as well as the instructions provided for my project. Please help me out! Sent from Windows Mail From: Ni'Yana Morgan Sent: ‎Friday‎, ‎March‎ ‎20‎, ‎2

[Tutor] Fastest find in 2 2D lists with else statement

2015-03-20 Thread Kale Good
Hello all, I'm new to python and a bit of a weekend-warrior programmer (guitar teacher by trade), so there are plenty of computer sciencey concepts that I haven't grasped yet, and I think I'm bumping up against those now. Read from separate csv files, I have something like a=[['bass',9],[

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Albert-Jan Roskam
- On Fri, Mar 20, 2015 8:05 PM CET Alan Gauld wrote: >On 20/03/15 09:37, Peter Otten wrote: > >> def close_relay(e=None,v=None,t=None): >> try: >> if not relay_closed() >>really_close_relay() >> except: >> really_close_relay() > >T

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Alan Gauld
On 20/03/15 09:37, Peter Otten wrote: def close_relay(e=None,v=None,t=None): try: if not relay_closed() really_close_relay() except: really_close_relay() The purpose of the if clause is to ensure that if the function is called many times you only close the

Re: [Tutor] Reversi Game Logic

2015-03-20 Thread Danny Yoo
> > So let's say that in the unit tests. Add assertions that we want > those four starred points to be legal moves. > > # > import unittest > > class ReversiTests(unittest.TestCase): > def testIslegalMoveOnExistingSpots(self): > logic = Rever

Re: [Tutor] Reversi Game Logic

2015-03-20 Thread Danny Yoo
Hi Ni'Yana, Here's a little transcript of what I'd do if I were to take a testing approach to the problem. --- Let's say that we start with a fresh board. Imagine that we've just created a fresh ReversiGameLogic. What does the board look like? Let's look at the state in the initializer. ###

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Peter Otten
Albert-Jan Roskam wrote: >>I would expect that >> >>try: >>main program here >>finally: >>close_relay() > > Is this (also) called a diaper pattern? Cool name, but most parents want the baby's faeces to go into the diapers whereas try ... bare except is notorious for swallowing useful informati

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Albert-Jan Roskam
On Fri, Mar 20, 2015 10:37 AM CET Peter Otten wrote: >Alan Gauld wrote: > >> On 20/03/15 02:57, Doug Basberg wrote: >> >> Still, I would like to know if a 'hook' exists on exit from Python. I am >> running Linux on a Raspberry Pi with Python 2.7.4 I also run an Apa

Re: [Tutor] Reversi Game Logic

2015-03-20 Thread Dave Angel
On 03/19/2015 08:50 PM, niyanax...@gmail.com wrote: I am having trouble with a function in my reversi logic code. The function is the isLegalMove I am asked to "Return a Boolean indicating if the current player can place their chip in the square at position (row, col). Both row and col must be

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Peter Otten
Alan Gauld wrote: > On 20/03/15 02:57, Doug Basberg wrote: > >> Still, I would like to know if a 'hook' exists on exit from Python. I am >> running Linux on a Raspberry Pi with Python 2.7.4 I also run an Apache >> server on the Pi for monitor and control of power, HVAC, and security. > > Your

Re: [Tutor] Reversi Game Logic

2015-03-20 Thread Alan Gauld
On 20/03/15 04:50, Danny Yoo wrote: Some instructors out there do not realize that unit testing is considered a standard technique for introductory programming. Ask, and maybe that will change. Sadly, unit tests are not considered a standard technique for introductory programming. At least n

Re: [Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Alan Gauld
On 20/03/15 02:57, Doug Basberg wrote: Still, I would like to know if a 'hook' exists on exit from Python. I am running Linux on a Raspberry Pi with Python 2.7.4 I also run an Apache server on the Pi for monitor and control of power, HVAC, and security. Your previous mail got you three optio

[Tutor] UPDATE: Is there a 'hook' to capture all exits from a python program?

2015-03-20 Thread Doug Basberg
I do real-time controls programming and I control a relay in a python program that must be turned off before the program ends. First, the program should never exit unless I do it explicitly. Is there a 'hook' to process before any exit (even if not expected). I must turn off that relay or harm m

Re: [Tutor] List comprehensions to search a list--amazing!

2015-03-20 Thread Peter Otten
Patrick Thunstrom wrote: The generalized problem: L = [V0, V1, ..., Vn], where V0 >= V1 >= V2 >= ... >= Vn . Find index i, such that V[i] >= Vt >= V[i + 1], where Vt is the test value being searched for. I need to know the indices i and i + 1, which I need to interpol