jaymem/locate-pi — pull request #1 by camh- (2014-11-06 11:19:43+00:00)
Title: Clean up code.

This is how I would have written it, leaving the structure mostly intact.

A few points:
* Use consistent string quotes. I prefer single-quotes, so I used that, but if you prefer double-quotes, use that throughout.
* "if not a == b" is the same as "if a != b" but easier to read
* Use str.format where you can instead of string concatenation. Since a few places were just using print, I just used multiple args to print instead of forming a new string.
* Use new-style print() instead of print
* Only call get_pi once - it is expensive as is scans the network. No need to call it more than once.
* Use "except Exception as e" instead of "except Exception, e". The former is the new form.
* Be more strict with matching the MAC address. Ensure it only starts with the given OUI
* Use RASPBERRY_PI_OUI as a name instead of a bare constant in the code. It is more descriptive and easier to understand.
* Force MAC address to upper case when matching since they are case-insensitive.
* Use one advanced feature: '{} Found at {}'.format(*pi_info). The *pi_info unpacks the tuple into the argument list. It is the same as saying .format(pi_info[0], pi_info[1])
* Reorder imports to be alphabetical. It is easier to find what you're looking for as the import list grows.

There may be other better approaches to what you're doing, but I was intending to keep the structure the same. For instance, you could loop around the y/n input until you get a valid answer. There may be a need for error handling around nmap.PortScanner(), etc. Leave all that for another day.