0

I'm trying to create a hierarchy of options. I'm able to create the first list of options:

  1. lemur
  2. gorillas
  3. chimps

if the user chooses option 1 for lemurs then I run the Lemur.LE() function cause I already imported the lemur module. They are then presented with another set of options:

  1. Brandy
  2. Cigars
  3. Shaving Cream
  4. Choose a different monkey.

option 4 runs a break which sends them back to the first list. I'm trying to repeat actions from the first architecture so that I can have them choose Shaven.SC() by importing when the function Lemur.LE() is called, but if I place the imports before the function starts then I get a fatal crash at the beginning when I first import lemur, if I call them from within' the LE() function then I get a strange indention exception. Thoughts? Am I making this harder on myself then necessary?

P.S.

Okay here's the Code:

begin = int(raw_input("""Options 1-6"""))
    elif begin == 3:
    L.Leg()
    elif begin == 6:
        print "Goodbye"
        exit()

Level 2:

def Leg():
    begin = int(raw_input("""options 1-5"""))
    elif begin == 2:
        import LegacyWT
    else:
        print "Returning to Main Menu."
        break
SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
DJG
  • 7
  • 2

2 Answers2

0

It's not clear what you are doing wrong without a code sample. In general import is a statement like any other and can be used in any scope. So:

def LE():
    ...
    if option == 'Shaving Cream':
        import Shaven
        Shaven.SC()
    elif option == ...

should work just fine.

Tyler Crompton
  • 12,284
  • 14
  • 65
  • 94
Jan Hudec
  • 73,652
  • 13
  • 125
  • 172
0

get a strange indention exception. Thoughts? Am I making this harder on myself then necessary?

Indentation exceptions are almost always caused by mixing tabs and spaces in the same file. If you are using a decent editor, you can set it to automatically convert tabs to spaces. If you are not using a decent, stop it, and use a decent editor.

SingleNegationElimination
  • 151,563
  • 33
  • 264
  • 304
  • I'm using Notepad++. If Python doesn't get along with it then I don't think its a problem with the editor not being decent. – DJG Mar 08 '11 at 08:55
  • @DJG: Notepad++ is certainly adequate for python. Here's another Stack overflow question that will tell you how to take care of those pesky tabs: http://stackoverflow.com/questions/455037/notepad-tabs-to-spaces – SingleNegationElimination Mar 08 '11 at 13:52