Return a tuple from a funtion and place into another function python
<p>This description may be a bit complicated so I will try to keep it short.</p>

<p>I have the following code that is working correctly...</p>

<pre><code>def singlelist():
    from datetime import datetime
    from subprocess import Popen
    from subprocess import PIPE
    output=Popen(["sar","-r"], stdout=PIPE).communicate()[0]
    date=datetime.now()
    date=str(date).split()[0]
    listtimeval=[]
    for line in output.split('\n'):
        if line == '' or 'Average' in line or 'kb' in line or 'Linux' in line or 'RESTART' in line:
            pass
        else:
            (time,ampm,field1,field2,field3,field4,field5,field6,field7) = line.split()
            listtimeval.append((time + " "+ ampm + "," + field3).split(','))
    updatelist= [ [str(date) + " " +x[0],x[1]] for x in listtimeval]
    return updatelist


val=singlelist()
</code></pre>

<p>...notice how time,ampm,etc are not defined previously...</p>

<p>I am trying to make this more dynamic as the output of sar will not always have the same number of columns. </p>

<p>What I want to do is this...</p>

<pre><code>def fields(method):
    if method == '-r':
        nf = (time,ampm,field1,field2,field3,field4,field5,field6,field7)
    return nf


def singlelist(nf):
    from datetime import datetime
    from subprocess import Popen
    from subprocess import PIPE
    output=Popen(["sar","-r"], stdout=PIPE).communicate()[0]
    date=datetime.now()
    date=str(date).split()[0]
    listtimeval=[]
    for line in output.split('\n'):
        if line == '' or 'Average' in line or 'kb' in line or 'Linux' in line or 'RESTART' in line:
            pass
        else:
            nf = line.split()
            listtimeval.append((time + " "+ ampm + "," + field3).split(','))
    updatelist= [ [str(date) + " " +x[0],x[1]] for x in listtimeval]
    return updatelist

method='-r'
nf=fields(method)
val=singlelist(nf)
</code></pre>

<p>However I am getting this...</p>

<pre><code>Traceback (most recent call last):
  File "./Logic.py", line 110, in &lt;module&gt;
    nf=fields(method)
  File "./Logic.py", line 58, in fields
    nf = (time,ampm,field1,field2,field3,field4,field5,field6,field7)
NameError: global name 'time' is not defined
</code></pre>

<p>How can I accomplish this?</p>
