python return - "name not defined"
<p>I'm trying to get this script to write information into a basic text file. I'm still learning python.</p>

<p>The problem lies here:</p>

<pre><code>file_text = """%s SHOOT DETAILS\n
Number of shoots:\t %s
Maximum range:\t %s
Number of firers:\t %s
Number of lanes active:\t %s
Number of details:\t %s
Troops per detail:\t %s
\n 
RANGE STAFF
Ammo NCO:\t %s
Medical Supervisor:\t %s
IC Butts:\t %s""" % (shoot_name, number_of_shoots, max_range, number_of_firers, number_of_lanes, number_of_details, size_of_details, ammo_nco, medical_supervisor, ic_butts)
</code></pre>

<p>The error message:
NameError: name 'number_of_details' is not defined</p>

<p>The above is (supposedly) written into a file with this:</p>

<pre><code>def generatedocument():
    file = open(file_name, 'w')
    file.write(file_text)
    os.startfile(file_name)
</code></pre>

<p>However I did define it earlier in the following function:</p>

<pre><code>def detailformation():
    number_of_details = number_of_firers / number_of_lanes
    return number_of_details
</code></pre>

<p>Identical problems occur for the size_of_details, defined:</p>

<pre><code>def detailsizer():
    size_of_details = number_of_firers / detailformation()
    return size_of_details
</code></pre>

<p>And also with the range staff chooser function, sometimes it gives me a similar error. They come from this function that randomly selects them from a list:</p>

<pre><code>def range_staff():
    print "\n"
    ammo_nco = (random.choice(fiveplatoon))
    print "Ammo NCO: "+ammo_nco
    fiveplatoon.remove(ammo_nco)
    medical_supervisor = (random.choice(fiveplatoon))
    print "Medical supervisor: "+medical_supervisor
    fiveplatoon.remove(medical_supervisor)
    ic_butts = (random.choice(fiveplatoon))
    print "IC Butts/Console: "+ic_butts
    fiveplatoon.remove(ic_butts)
    return range_staff
</code></pre>

<p>It seems like I'm missing something fundamental here. How can I get python to recognise?</p>