Problems extending python array declared outside of scope
<p>This is a very basic question, but I can't seem to extend an array with a new item  that is added within a function. I haven't gotten push to work either, so I think my array is just not being addressed by the other functions. </p>

<p>The array is declared as a global because otherwise function(s) do not appear to be able to see it. There is probably a much better way, but this is working in a few ways.</p>

<p>this is one set of things I've tried:</p>

<pre><code>        # addTo.insert(0, theItem)
        # weeklytasks.append(theItem)
        # print(addTo) 
        # def askForItem(theItem):
        #     addTo.push(theItem)
        #     print(addTo)
        #
</code></pre>

<p>but no luck.</p>

<pre><code> def initializer():
            print("hello!")
            print("do you want to view the current list, or add a new item?")
</code></pre>

<p>setting up some arrays</p>

<pre><code>        global weeklyTasks = ['no items'];
        global monthlyTasks = ['no items']
        global quarterlyTasks = ['no items'];
</code></pre>

<p>trying to extend</p>

<pre><code>        quarterlyTasks.extend('the item')
        print(quarterlyTasks);
</code></pre>

<p>Neither of these work</p>

<pre><code>        #monthlyTasks.push(0,"task1")
        #monthlyTasks.append("item")
</code></pre>

<p>set a var for user's input</p>

<pre><code>        global theItem
        addTo = ""
        theItem = ""


        import string
        print('addTo in globals, ' 'addTo' in globals()) 
</code></pre>

<p>takes an item and checks its timeframe</p>

<pre><code>        def evaluateInput(timeframe):

            global addTo;
            global theItem;
            if timeframe == "Weekly":
                addTo = "weeklyTasks";
                printDestination();
                weeklyTasks.extend(theItem); # why does [].extend not work here?

            if timeframe == "Monthly":
                 addTo = "monthlyTasks"
                 monthlyTasks.insert(0,theItem)
                 printDestination()
            if timeframe == "Quarterly":
                 addTo = "quarterlyTasks"
                 quarterlyTasks.insert(0,theItem)
                 printDestination()
</code></pre>

<p>follow up with a request for the timeframe</p>

<pre><code>      def getTimeframe(text): 
        if "add" in text: 
            timeframe = input("Where does this entry go? \n Weekly, Monthly or Quarterly?: ")
            evaluateInput(timeframe) # sends the timeframe to evaluateInput

            # next, ask for the item
            theItem = input('what is the item?')
</code></pre>

<p>print a confirmation of what is being added where</p>

<pre><code>        def printDestination():
            print("The item (" + theItem+") will be added to " + addTo)
            # prints where something is going
            print("the "+addTo+" list now contains:") # good, this worked
            print(weeklyTasks) #good, this worked (but the method to push doesn't work)
</code></pre>

<p>A working example of all mentioned functions. <code>global</code> is not required, because the <code>tasklist</code> is not re-assigned in the function, only its methods are called.</p>

<pre><code>tasklist = ['one']

def testfunc():
    # no global required
    tasklist.append('two')
    tasklist.extend(['three', 'four'])
    tasklist.insert(0, 'zero')

testfunc()
print(tasklist)
# ['zero', 'one', 'two', 'three', 'four']
</code></pre>

<p>Hope it helps.</p>

python arrays python-3.x