[Tutor] multi processes or threads?

2012-09-03 Thread richard kappler
I'm not sure which direction to go.  I need to be able to run multiple
?processes? ?threads? (not sure which) concurrently.  I'm working on AI for
a robot and because I'm not sure what direction to go I'll use the term
"thread" to illustrate my question, realizing threads may not be what I'm
looking for.  The bot would have several "threads" running concurrently so
as to be aware of it's state, such as a vision thread, an object and face
recognition thread, a chat thread, a command and control thread, a nav
thread, you get the idea.  In order to do this in python, should I be
looking at threads, multiprocessing, something else or is this not
practicable in python?

regards, Richard

-- 
Eat a live toad the first thing in the morning and nothing worse will
happen to you the rest of the day.
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running more than one python program at the same time

2012-09-03 Thread Benjamin Fishbein
Hi. I started running the program in the terminal rather than IDLE. It works, 
and I can run several programs at the same time. The problem is that when the 
program is finished running, it prints:
exit status: 0
logout

[Process completed]

And I can't access the data that the program returned. Do I need the program to 
be saved to a text file, or is there a way to simply print it out? It's a small 
amount of data, and I'd rather just print it out.
Ben

On Aug 29, 2012, at 9:24 AM, Marc Tompkins wrote:

> On Tue, Aug 28, 2012 at 7:35 PM, Steven D'Aprano  wrote: 
>  
> 
> In Windows, that is the DOS prompt -- either cmd.com or command.exe, I never 
> remember which one is which.
> 
> I'm pretty sure that was intentional, but just in case...
> 
> In MS-DOS/PC-DOS, and in 16-bit versions of Windows (up to Windows 98/Me, in 
> other words), the command interpreter is COMMAND.COM
> 
> In 32-bit versions of Windows, you can still use the 16-bit interpreter if 
> you want - although it's deprecated, and has been removed entirely in 64-bit 
> Windows - but the native 32-bit command interpreter is CMD.EXE
> 
> (I used all-caps for emphasis without requiring HTML formatting, but in fact 
> Windows is generally case-insensitive.)
> ___
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running more than one python program at the same time

2012-09-03 Thread William R. Wing (Bill Wing)
On Sep 3, 2012, at 11:01 AM, Benjamin Fishbein  wrote:

> Hi. I started running the program in the terminal rather than IDLE. It works, 
> and I can run several programs at the same time. The problem is that when the 
> program is finished running, it prints:
> exit status: 0
> logout
> 
> [Process completed]
> 
> And I can't access the data that the program returned. Do I need the program 
> to be saved to a text file, or is there a way to simply print it out? It's a 
> small amount of data, and I'd rather just print it out.
> Ben
> 

Ben, You will probably get several answers to this, since there are several 
ways to solve the issue.  The simplest (sort of kludgy) solution is simply to 
make the last line in your program be:

junk = raw_input("Yes Master?")

and when your program hits this line, it will print out "Yes Master?" in the 
terminal window and then sit there waiting for you to type something terminated 
by a  key.  For future reference, what you've typed goes into the 
variable junk.  This is a dead easy way to get interactive data into ANY future 
python script you write.

-Bill

PS:  this assumes you are running python 2.x.  In python 3.x, raw_input has 
been renamed input, but it works the say way.

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] multi processes or threads?

2012-09-03 Thread Alan Gauld

On 03/09/12 15:04, richard kappler wrote:


what I'm looking for.  The bot would have several "threads" running
concurrently so as to be aware of it's state, such as a vision thread,
an object and face recognition thread, a chat thread, a command and
control thread, a nav thread, you get the idea.  In order to do this in
python, should I be looking at threads, multiprocessing, something else
or is this not practicable in python?


Threads. Multiple processes would be overkill for this.

And yes its fine in Python. Check out the threading module.
Several online tutorials on how to use it too.

My only caveat is not to have too many, especially
conflicting controls. For example anything that causes the bot to move 
should be in a single thread or you wind up with two threads competing 
with each other to move the bot in two directions at once. Similarly 
vision and face recognition could conflict.


Hopefully you get my drift.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running more than one python program at the same time

2012-09-03 Thread Alan Gauld

On 03/09/12 16:01, Benjamin Fishbein wrote:

Hi. I started running the program in the terminal rather than IDLE. It
works, and I can run several programs at the same time. The problem is
that when the program is finished running, it prints:
exit status: 0
logout

[Process completed]


That is probably writing to stderr so you can redirect the stderr output 
to a file (or /dev/null if you're feeling confident!)


$ python myprog.py myargs 2> myprog.err &

runs myprog.opy in the background and redirects stderr to the file 
myprog.err. You can then open mpyprog.err in any text editor to read it 
if you wish - hopefully it will be very boring!



And I can't access the data that the program returned. Do I need the
program to be saved to a text file, or is there a way to simply print it
out? It's a small amount of data, and I'd rather just print it out.


It should print to stdout so you can see it but in general its probably 
better to redirect that to a file too... Especially if you have multiple 
programs in one terminal! So your command lines should probably look like


$ python myprog.py myargs 2> myprog.err 1> myprog.out &


HTH

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running more than one python program at the same time

2012-09-03 Thread Oscar Benjamin
On Mon, 03 Sep 2012 18:55:43 +0100, Alan Gauld 
 wrote:

On 03/09/12 16:01, Benjamin Fishbein wrote:
> Hi. I started running the program in the terminal rather than 

IDLE. It
> works, and I can run several programs at the same time. The 

problem is

> that when the program is finished running, it prints:
> exit status: 0
> logout
>
> [Process completed]


What do you mean when you say you ran the program in the terminal? Do 
you mean that you opened a terminal window and then typed 'python 
myprog.py'? Or did you click on the python file and choose 'run in 
terminal' or similar? That output looks to me like what happens on 
OSX when a terminal window is open but the shell has been closed.


I think the instruction to run in a terminal should look like:
1) open the terminal (how to do this depends on your OS).
2) type 'cd /path/to/my/script/folder' and then hit enter.
3) type 'python script.py' and then hit enter.

Is that similar to what you're doing?

Oscar

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] multi processes or threads?

2012-09-03 Thread Dwight Hutto
Think assembly, or procedural with this, and how the mind of a CPU works.
Instructional steps toward an endpoint.

Your mind works the fastest when one problems is given, and is being
solved, otherwise allocation of certain areas take place in order to find a
rewarding solution.

Not having used threads in the past, I would suggest that you know there
has to be either equal allocation of time, or priority based in order to
perform each procedure given in threading, until there is a final result.

My first thought on giving computers imagination was monkeys banging on a
keyboard, until Shakespeare shot out(Me thinks it a weasel). Now it's
interlocking molecular vectors, and run simulations which is much more
difficult, but defined algorithmically, and procedurally, unless you
network several cpus and allocate to each a specific
thought/theory/hypothesis to process.

-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a script in the background

2012-09-03 Thread Dwight Hutto
On Sun, Sep 2, 2012 at 9:03 PM, Steven D'Aprano  wrote:

> On Sun, Sep 02, 2012 at 03:14:53PM -0700, Ray Jones wrote:
> > This is only tangentially related to the thread. Someone mentioned that
> > so long as a script didn't require user input or output to the user, it
> > could run silently in the background. But is there a way for a Python
> > (2.7.3) script to determine whether it was called by the user or called
> > by something like cron or kalarm? That way user inputs could be used
> > when called by a user, but defaults could be used if run by a bot.
>
> The usual way to detect this is by checking whether or not there is a
> terminal available.
>
> os.isatty(sys.stdout.fileno())
>
> If the script is running directly in a console, isatty will return True;
> if it is running from cron, or via a pipe or similar, then it will
> return False.


But a script is always running in the background of the OS main console of
the upfront GUI app users usually see, correct?

Cron has to coninually run, or have another process that checks x number
per minute(hertz of the process) to see what is going on, so it all goes
back to a main script in OS runtime checking for processes to run, even for
other processes, for other processes, etc.

-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a script in the background

2012-09-03 Thread Dwight Hutto
>
> Cron or another process that oversees cron has to continually run.
>

> --
> Best Regards,
> David Hutto
> *CEO:* *http://www.hitwebdevelopment.com*
>
>


-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a script in the background

2012-09-03 Thread Alan Gauld

On 03/09/12 22:46, Dwight Hutto wrote:


But a script is always running in the background of the OS main console
of the upfront GUI app users usually see, correct?


Not every OS has a main console behind the GUI, but in the case of *nix 
its true.


On *nix there is a cron daemon that runs in the background.
but one job running in the background controlling dozens(?) of others is 
way more efficient than dozens of programs all running idle in the 
background and periodically springing into action.



back to a main script in OS runtime checking for processes to run, even
for other processes, for other processes, etc.


Ultimately it all goes back to the OS scheduler which constantly swaps 
processes in and out of run mode...


--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] multi processes or threads?

2012-09-03 Thread Alan Gauld

On 03/09/12 22:32, Dwight Hutto wrote:

Think assembly, or procedural with this, and how the mind of a CPU
works. Instructional steps toward an endpoint.

Your mind works the fastest when one problems is given, and is being
solved, otherwise allocation of certain areas take place in order to
find a rewarding solution.

Not having used threads in the past, I would suggest that you know there
has to be either equal allocation of time, or priority based in order to
perform each procedure given in threading, until there is a final result.

My first thought on giving computers imagination was monkeys banging on
a keyboard, until Shakespeare shot out(Me thinks it a weasel). Now it's
interlocking molecular vectors, and run simulations which is much more
difficult, but defined algorithmically, and procedurally, unless you
network several cpus and allocate to each a specific
thought/theory/hypothesis to process.



I have no idea what all that means!
Nor how it relates to the OPs question.

--
Alan G
Author of the Learn to Program web site
http://www.alan-g.me.uk/

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] multi processes or threads?

2012-09-03 Thread Dwight Hutto
On Mon, Sep 3, 2012 at 7:59 PM, Alan Gauld wrote:

> On 03/09/12 22:32, Dwight Hutto wrote:
>
>> Think assembly, or procedural with this, and how the mind of a CPU
>> works. Instructional steps toward an endpoint.
>>
>> Your mind works the fastest when one problems is given, and is being
>> solved, otherwise allocation of certain areas take place in order to
>> find a rewarding solution.
>>
>> Not having used threads in the past, I would suggest that you know there
>> has to be either equal allocation of time, or priority based in order to
>> perform each procedure given in threading, until there is a final result.
>>   I'm working on AI for a robot and because I'm not sure what direction
>> to go I'll use the term "thread" to illustrate my question, realizing
>> threads may not be what I'm looking for.
>> My first thought I'm working on AI for a robot and because I'm not sure
>> what direction to go I'll use the term "thread" to illustrate my question,
>> realizing threads may not be what I'm looking for. on giving computers
>> imagination was monkeys banging on
>> a keyboard, until Shakespeare shot out(Me thinks it a weasel). Now it's
>> interlocking molecular vectors, and run simulations which is much more
>> difficult, but defined algorithmically, and procedurally, unless you
>> network several cpus and allocate to each a specific
>> thought/theory/hypothesis to process.
>>
>>
> I have no idea what all that means!
> Nor how it relates to the OPs question.
>

>From the OP:

 I'm working on AI for a robot and because I'm not sure what direction to
go I'll use the term "thread" to illustrate my question, realizing threads
may not be what I'm looking for.


Tell me Alan, what is threading within a CPU, coming from a higher level
language, that passes through a processor executing one instruction at time
from the instruction pointer, unless otherwise designed from multiple
instructions through separate cpu's(i.e. real thread commands)?


-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a script in the background

2012-09-03 Thread Dwight Hutto
On Mon, Sep 3, 2012 at 7:57 PM, Alan Gauld wrote:

> On 03/09/12 22:46, Dwight Hutto wrote:
>
>  But a script is always running in the background of the OS main console
>> of the upfront GUI app users usually see, correct?
>>
>
> Not every OS has a main console behind the GUI, but in the case of *nix
> its true.
>
> On *nix there is a cron daemon that runs in the background.
> but one job running in the background controllingfat boy slim dozens(?) of
> others is way more efficient than dozens of programs all running idle in
> the background and periodically springing into action.
>

But each OS(BIOS handler) has a way of providing/accepting instructions to
the processor, which is constantly procedural. This has to have a terminal
at some point.

What is meant by behind a console, and running without a console, just a
window system, and a file set that deals with instructions/errors based on
BIOS input/output?


-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] running more than one python program at the same time

2012-09-03 Thread Steven D'Aprano

On 04/09/12 01:01, Benjamin Fishbein wrote:

Hi. I started running the program in the terminal rather than IDLE. It works,
and I can run several programs at the same time. The problem is that when the
program is finished running, it prints:
exit status: 0
logout

[Process completed]



Which terminal is that? I've never come across a terminal with that behaviour.



And I can't access the data that the program returned.


Programs don't return data. They can output data to a file or pipe, or print to
the screen.

The execution model of functions within a program and of the program itself are
quite different and you need to wrap your brain around the differences.

Normally, you would output your program's result to a file-like thing. Two
common idioms used by most command-line tools are:

1) the program always writes data to "standard output" (stdout); the caller can
   re-direct stdout using the usual pipe and redirection operators;

2) the program takes a command-line argument telling it which file to write to;
   if no file name is given, you can write to a default file, or stdout as
   above, or print an error message and stop.


Variations include "verbose mode", that formats the result in a nice, human-
readable format intended for human readers, and "terse mode" intended to be
piped to another program.

I recommend you study the various conventions of the command-line tools on
your operating system.

In Python, normally you would divide your program into two separate layers:

* a calculation layer that calculates the result you need;

* a display layer that is responsible for output.

That allows you to easily separate the two parts of the problem: you can
isolate "display bugs" from "calculation bugs", test and debug each
separately, and even use the calculation functions from other Python code.

The display layer might be as simple as the print command:


if __name__ == '__main__':
result = do_some_calculation()
print(result)


Last but not least, to be a "well-behaved" command line tool, you should
set the return code. The easiest way to do this from Python is with
sys.exit:

import sys

if an_error_occurred:
sys.exit(error_code)
else:
sys.exit(0)

There are supposed to be conventions for what the error codes mean,
but nobody agrees on them. The easiest is to just return 1 or 2
to mean "an error occurred".




--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


[Tutor] making a shortcut in windows

2012-09-03 Thread Garry Willgoose
I want to put a shortcut onto the desktop in windows (XP and later) in Python 
2.6 or later. In Unix its easy using os.symlink but I can't find anything 
equivalent for windows. My searches on the web led me to the code below but the 
code returns the error

AttributeError: function 'CreateSymbolicLinkW' not found

so does anybody have any suggestions?




__CSL = None

def create_alias(source, linkname):
  """
  Each operating system has a different way of creating an alias.  
  This is the windows version
  """
  import os
  try:
global __CSL
if __CSL is None:
  import ctypes
  csl = ctypes.windll.kernel32.CreateSymbolicLinkW
  csl.argtypes = (ctypes.c_wchar_p, ctypes.c_wchar_p, ctypes.c_uint32)
  csl.restype = ctypes.c_ubyte
  __CSL = csl
flags = 0
if source is not None and os.path.isdir(source):
  flags = 1
if __CSL(linkname, source, flags) == 0:
  raise ctypes.WinError()  
  except:
print(' Error creating a file alias from '+str(source)+' to 
'+str(linkname))
  return()

___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a script in the background

2012-09-03 Thread Steven D'Aprano

On 04/09/12 10:26, Dwight Hutto wrote:


On *nix there is a cron daemon that runs in the background.
but one job running in the background controlling dozens(?) of
others is way more efficient than dozens of programs all running idle in
the background and periodically springing into action.



But each OS(BIOS handler) has a way of providing/accepting instructions to
the processor, which is constantly procedural. This has to have a terminal
at some point.

What is meant by behind a console, and running without a console, just a
window system, and a file set that deals with instructions/errors based on
BIOS input/output?


I'm afraid these sentences sound like gobbledygook to me. No offense Dwight,
but it sounds like you're randomly inserting "computer terms" into sentences
with no meaning.

The only part that actually makes sense to me is:

"This has to have a terminal at some point."

but that is not true. The fact that cron runs without a tty (a terminal) is
proof of that.



--
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] Running a script in the background

2012-09-03 Thread Dwight Hutto
On Mon, Sep 3, 2012 at 9:56 PM, Steven D'Aprano  wrote:

> On 04/09/12 10:26, Dwight Hutto wrote:
>
>  On *nix there is a cron daemon that runs in the background.
>>> but one job running in the background controlling dozens(?) of
>>>
>>> others is way more efficient than dozens of programs all running idle in
>>> the background and periodically springing into action.
>>>
>>>
>> But each OS(BIOS handler) has a way of providing/accepting instructions to
>> the processor, which is constantly procedural. This has to have a terminal
>> at some point.
>>
>> What is meant by behind a console, and running without a console, just a
>> window system, and a file set that deals with instructions/errors based on
>> BIOS input/output?
>>
>
>
> On Mon, Sep 3, 2012 at 9:56 PM, Steven D'Apran
>
> Best regards,
> o  wrote:
>
>> On 04/09/12 10:26, Dwight Hutto wrote:
>>
>>  On *nix there is a cron daemon that runs in the background.
 but one job running in the background controlling dozens(?) of

 others is way more efficient than dozens of programs all running idle in
 the background and periodically springing into action.


>>> But each OS(BIOS handler) has a way of providing/accepting instructions
>>> to
>>> the processor, which is constantly procedural. This has to have a
>>> terminal
>>> at some point.
>>>
>>> What is meant by behind a console, and running without a console, just a
>>> window system, and a file set that deals with instructions/errors based
>>> on
>>> BIOS input/output?
>>>
>>
>> I'm afraid these sentences sound like gobbledygook to me. No offense
>> Dwight,
>> but it sounds like you're randomly inserting "computer terms" into
>> sentences
>> with no meaning.
>>
>> Which one's. If yuou could, please reply on a line by line, because some
of what you listed above isn't mine.

What's wrong with:



But each OS(BIOS handler) has a way of providing/accepting instructions to
the processor, which is constantly procedural. This has to have a terminal
at some point.

What is meant by behind a console, and running without a console, just a
window system, and a file set that deals with instructions/errors based on
BIOS input/output?

I'll add Intel/AMD to the instructions secton.

 The gobbledy gook, might be a little smeared on your face...Want a
rag?...Steven

By the way, you can call me David...buddy.


The only part that actually makes sense to me is:
>>
>>
>> "This has to have a terminal at some point."
>>
>> but that is not true. The fact that cron runs without a tty (a terminal)
>> is
>> proof of that.
>>
>>
>>
>> --
>> Steven
>>
>> ___
>> Tutor maillist  -  Tutor@python.org
>> To unsubscribe or change subscription options:
>> http://mail.python.org/mailman/listinfo/tutor
>>
>
> I'm afraid these sentences sound like gobbledygook to me. No offense
> Dwight,
> but it sounds like you're randomly inserting "computer terms" into
> sentences
> with no meaning.
>
> The only part that actually makes sense to me is:
>
>
> "This has to have a terminal at some point."
>
> but that is not true. The fact that cron runs without a tty (a terminal) is
> proof of that.
>
>
>
> --
> Steven
>
> __**_
> Tutor maillist  -  Tutor@python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/**mailman/listinfo/tutor
>



-- 
Best Regards,
David Hutto
*CEO:* *http://www.hitwebdevelopment.com*
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor


Re: [Tutor] making a shortcut in windows

2012-09-03 Thread Steven D'Aprano
On Tue, Sep 04, 2012 at 11:57:48AM +1000, Garry Willgoose wrote:

> I want to put a shortcut onto the desktop in windows (XP and later) in 
> Python 2.6 or later. In Unix its easy using os.symlink but I can't 
> find anything equivalent for windows. My searches on the web led me to 
> the code below but the code returns the error
> 
> AttributeError: function 'CreateSymbolicLinkW' not found

If you expect us to actually debug the error, you need to give the right 
debugging information. That means you have to show the FULL traceback 
printed, not just the final error message without any context. Do not 
retype the error from memory, or summarise it, do a copy and paste of 
the entire traceback, starting with the line

Traceback (most recent call last):

all the way to the end. And then make sure that the code you are giving 
us is the same as the code you are running. I say this because I believe 
that the code you sent us is not the code you are running. I cannot see 
any possible way for the code you gave to raise AttributeError.

But in this case, I recommend against using ctypes. Here are some better 
ways to manage Windows shortcuts:

http://www.blog.pythonlibrary.org/2010/01/23/using-python-to-create-shortcuts/

http://mail.python.org/pipermail/python-win32/2003-March/000862.html


> __CSL = None
> 
> def create_alias(source, linkname):
>   """
>   Each operating system has a different way of creating an alias.  
>   This is the windows version
>   """

That's technically incorrect. *Alias* (MacOS), *shortcut* (Windows) and 
*symlink* (Linux, Unix, MacOS, and others) are all slightly different 
things, although they all solve more-or-less the same problem. In 
principle you could have a single OS offer all three. MacOS offers both 
aliases and symlinks.

(And even more pedantically: it isn't the *operating system* which 
matters, but the file system. So Windows with a Linux file system could 
have symlinks.)



>   import os
>   try:
[...]
>   except:
> print(' Error creating a file alias from '+str(source)+' to 
> '+str(linkname))

Please never, ever, ever do that. Every time somebody writes an except 
block that catches everything like that, god kills a kitten.

Catch-all exceptions like that are one of the worst bad-ideas in Python 
ever. The problems include:

* They catch too much -- not only do they catch legitimate errors that 
  should be caught, but they catch non-errors like KeyboardInterrupt 
  which *don't* indicate an error.

* They mask programming bugs -- because they catch too much, they hide 
  programming bugs which should be exposed with a traceback so that you 
  can fix them.

* They give you no way to access the exception caught.

* They tempt beginners into thinking that they have to *hide problems*
  by catching the exception and just printing a message, instead of 
  *fixing problems* so no exception happens in the first place.


There are exceptions (pun not intended) to the rule "never use a bare 
except", but they're rare.

In general, a try...except block should:

* always explicitly state the exception(s) you want to catch;

* cover only the minimum amount of code necessary.


>   return()

That line is wrong -- it returns an empty tuple (). To return nothing, 
just say "return" on its own, or better still, don't say anything and 
the function will return nothing when it is finished.

(To be precise: it will return the None object.)


-- 
Steven
___
Tutor maillist  -  Tutor@python.org
To unsubscribe or change subscription options:
http://mail.python.org/mailman/listinfo/tutor