On May 12, 1:33 pm, mrstevegross <mrstevegr...@gmail.com> wrote: > I have a python script that is pretty simple: when executed, it > imports a bunch of stuff and then runs some logic. When *imported*, it > defines some variables and exits. Here's what it looks like: > > === foo.py === > if __name__ != '__main__': > x = 1 > exit_somehow > > import bar > do_some_stuff... > === EOF === > > There's a problem, though. On line 3, I wrote "exit_somehow". > Actually, I have no idea how to do that part. Is there some way I can > get python to abandon processing the rest of the script at that point? > I know goto doesn't exist, so that's not an option... sys.exit() won't > work, because that will abort the entire python interpreter, rather > than just the evaluation of the module. > > Thanks, > --Steve
Isn't abandoning the processing of the rest of the script exiting the script? You could use "return" or wrap the offending code in a try/ except block and do something on an exception... Mike -- http://mail.python.org/mailman/listinfo/python-list