Python Recipe for NSF Proposals

In a recent Politico article, “No, the GOP is Not at War with Science”, Senator Rand Paul and Representative Lamar Smith addressed criticism of the GOP’s attempt to undermine the peer review process of the National Science Foundation and National Institute of Health’s grant proposal system.

In their article, Paul and Smith cite what they suggest are frivolous expenditures on research that do not advance national interests. I will not name the studies listed by Paul and Smith, but I do encourage people to read the original article to understand the jeers in context.

I will, however, cite one of Paul and Smith’s justifications for their argument:

Our national debt is more than $18 trillion, and the American taxpayer is hurting. If we, as a country, have decided to spend taxpayers’ hard-earned dollars on funding science and research, then we need to spend wisely. Every dollar spent by the federal government must be spent just as the typical family deals with spending decisions on car payments, child care, food purchases and housing needs.

Read more:

In order to help researchers appeal to the financial and national scruples of the Republican controlled Congress, I have written a short script that will automatically generate a GOP-friendly NSF grant proposal description in Word.

The Python code (below) requires only the python-docx and lxml >= 2.32 packages that can be downloaded through pip.

__author__ = 'Ryan Omizo'

#Requires python-docx package
#Requires lxml >=2.3.2

from docx import Document
import random

def guns_references():
    dates = [2001, 2007, 2012, 1998, 2002, 2003, 2010, 1985, 1997]
    references = ['Guns, Gun. Gun. (' + str(dates[i]) + '). Guns. Guns: Guns.' for i in range(len(dates))]

    return references

def guns_intext():
    dates = [2001, 2007, 2012, 1998, 2002, 2003, 2010, 1985, 1997]
    in_text = ['(Guns, ' + str(dates[i]) + ')' for i in range(len(dates))]

    return in_text

def guns_sentence():
    g = 'guns'
    word_count = random.randrange(7,13)

    word_list = []
    for i in range(word_count):

    word_list.insert(0, 'Guns')

    return ' '.join(map(str, word_list))

def guns_paragraph():
    sentence_count = random.randrange(7,20)

    sentence_list = []
    for i in range(sentence_count):

    in_text = guns_intext()
    s = sentence_list[random.randrange(len(sentence_list))].split()
    s.insert(len(s)/2, in_text[random.randrange(len(in_text))])

    t = ' '.join(map(str, s))
    sentence_list.insert(random.randrange(len(sentence_list)), t)

    return ' '.join(map(str, sentence_list))

def guns_section():
    paragraph_count = random.randrange(7,15)

    paragraph_list = []
    for i in range(paragraph_count):

    return paragraph_list

def guns_headings():
    r = ['I.', 'II.', 'III.', 'IV.', 'V.', 'VI.']

    headings = [r[i] + ' Guns' for i in range(len(r))]
    return headings

def guns_subheadings():
    r = range(4)[1:]
    subheadings = [str(r[i]) + '. ' + guns_paragraph()  for i in range(len(r))]
    return subheadings

document = Document()
document.add_heading('Guns', 0)

gh = guns_headings()

for i in range(len(gh)):
    if i == 1:
        gsh = guns_subheadings()
        gs1 = guns_section()
        for item in gsh:
        for x in gs1:
    elif i == 3:
        gsh = guns_subheadings()
        gs1 = guns_section()
        for item in gsh:
        for x in gs1:
    elif i == 4:
        recordset = [1.1, 1.2, 1.3, 2.1, 2.2, 2.3, 3.1, 3.2, 3.3]
        table = document.add_table(rows=1, cols=4)
        hdr_cells = table.rows[0].cells
        hdr_cells[0].text = 'Guns and Sub-machine guns'
        hdr_cells[1].text = 'Year 1'
        hdr_cells[2].text = 'Year 2'
        hdr_cells[3].text = 'Year 3'
        for i in range(len(recordset)):
            row_cells = table.add_row().cells
            row_cells[0].text = str(recordset[i])
            row_cells[1].text = 'Guns'
            row_cells[2].text = 'Guns'
            row_cells[3].text = 'Guns'
        gs2 = guns_section()
        for g in gs2:

document.add_heading('References Cited')
citations = guns_references()
for citation in citations:

Running this code in your favorite Python environment or command line will output an editable Word doc such as the following:


Download (PDF, Unknown)