View Single Post
Old Nov 24th, 2007, 12:01 PM   #8
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
Re: Question Number 1

I think the key is in the OP's second post:
Quote:
when Python first loads up and I imported the script.
In BoaConstructor, this fails:
UnboundLocalError: local variable 'twentysevenLines' referenced before assignment
modules = {}

def main ():
    print "First Line."
    twentysevenLines()
    print "Second Line."

def newLine():
    print
def threeLines():
    newLine()
    newLine()
    newLine()
def nineLines():
    threeLines()
    threeLines()
    threeLines()
def twentysevenLines():
    nineLines()
    nineLines()
    nineLines()

if __name__ == '__main__':
    main()
but this works:
from precmod import *
modules ={'precmod': [0, '', 'precmod.py']}

def main ():
    print "First Line."
    twentysevenLines()
    print "Second Line."

if __name__ == '__main__':
    main()
precmod.py
def newLine():
    print
def threeLines():
    newLine()
    newLine()
    newLine()
def nineLines():
    threeLines()
    threeLines()
    threeLines()
def twentysevenLines():
    nineLines()
    nineLines()
    nineLines()
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code.
Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers
DaWei is offline   Reply With Quote