How to break out of two nested for loops?

Francois Petitjean littlejohn.75 at free.fr
Mon Jan 21 18:38:48 EST 2002


>well an easy way to break out of n loops is using an exception.

>class BreakLoop(Exception) : pass

Wow!  Thanks for your answer(so fast!)

Another (easy) question :
If in a moduleA, I write
import B
B is bound to module B (in the A namespace). How, in module B, to write a
function which returns a tuple with moduleB and an object defined in B?

For example, if I write Interpreter.py with
class Interpreter:
...

interpreter = Interpreter()
def Mod_Obj():
    """returns a tuple (InterpreterModule, interpreter)"""
    current = __import__(__name__)   # This is OK in the   if __name__ ==
'__main__': case
    return (current,interpreter)

And is using the same word (Interpreter) for a module (Interpreter.py) anda
class, an issue?
import Interpreter
mobj = Interpreter.Mod_Obj()
assert mobj[0] is Interpreter   #  true?


Regards





More information about the Python-list mailing list