How do I pass a new dictionary name as a parameter to a function in Python?
<p>I'm a new programmer and am having issues with passing a new dictionary name as a parameter to a function.<br>
I'm trying to create a function that will pull down data from a webpage and create a dictionary key for the hostname and a value of the full line of data.  There are multiple pages that have the commonality of the hostname as a key value, which I will eventually join together in a single row.  </p>

<p>First, I create a list called <code>control</code> used as a key file of all the hosts I'm searching for.  I then pass the values <code>webpage</code>, <code>delimiter</code>, and <code>dictionary name</code> to the function.<br>
When doing this, it seems the name of the dictionary is not being passed to the function.  </p>

<pre><code>#open key file
f = open("./hosts2", "r")
control = []
for line in f:
    line = line.rstrip('\n')
    line = line.lower()
    m = re.match('(^[\w\d]+)', line)
    control.append(m.group())
# Close key file
f.close()

def osinfo(url, delimiter, name=None):
    ufile = urllib2.urlopen(url)
    ufile.readline()
    name = {}
    for lines in ufile.readlines():
        lines = lines.rstrip("\n")
        fields = lines.split(delimiter)
        m = re.match(r'(?i)(^[a-z0-9|\.|-]+)', fields[1].lower())
        hostname = m.group()
        if hostname in control:
            name[hostname] = lines
    print "The length of osdata inside the function:", len(name)

osdata = {}
osinfo(‘http://blahblah.com/test.scsv’, ';', name='osdata')
print "The length of osdata outside the function", len(osdata)
</code></pre>

<p>The output is as follows:</p>

<pre><code>$./test.py
The length of osdata inside the function: 11
The length of osdata outside the function: 0
</code></pre>

<p>It seems that the keyword is not being picked up by the function.</p>

<p>Is this due to scope?</p>
