I'm trying to get this script to write information into a basic text file. I'm still learning python.
The problem lies here:
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)
The error message: NameError: name 'number_of_details' is not defined
The above is (supposedly) written into a file with this:
def generatedocument():
file = open(file_name, 'w')
file.write(file_text)
os.startfile(file_name)
However I did define it earlier in the following function:
def detailformation():
number_of_details = number_of_firers / number_of_lanes
return number_of_details
Identical problems occur for the size_of_details, defined:
def detailsizer():
size_of_details = number_of_firers / detailformation()
return size_of_details
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:
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
It seems like I'm missing something fundamental here. How can I get python to recognise?