Python alternative to import
Question: I've got the following code:

    
    
    def main():
        #init
         #Load config.
        import localconfig
        print localconfig.name
         #update mac adress db, if at all possible:
        try:
            from maclist import maclist
        except:
            import urllib2
            print "Fetching MAC adress db."
            maclist = urllib2.urlopen(localconfig.url)
            fl = open("maclist.py","w")
            fl.write(
    "#maclist.py generated by "+localconfig.name+"""
    #Based on """+localconfig.url+"""
    maclist = {}
    """)
            print "Generating maclist.py"
            for line in maclist:
                if "#" in line: line=line[:line.index("#")]
                line = line.split()
                if line:
                    if "-" in line[0]:
                        line[0]=line[0].replace("-",":")
                    if "/" in line[0]:
                        ndex = line[0].index("/")
                        ndex = (int(line[0][ndex+1:])//8)*3
                        line[0]=line[0][:ndex-1]
                    line=[repr(part) for part in line]
                    line = "maclist["+line[0]+"]="+line[1]
                    fl.write("=".join(line.split())+"\n")
            fl.close()
        from maclist import maclist
        print "Succesfully loaded maclist.py"
    

This does work, but I don't like the fact that I'm importing (and thus
running) something I downloaded from the interweb. Is there a better way to go
about this? (Remember, I don't want to redownload every time, only if it's the
first time (or if it's been deleted)).


Answer: I suggest you learn how to use JSON, so you can just have a file like this:

    
    
    {<id>:<mac>,<id>:<mac>}
    

(Yes, it's similar to Python's `dict` and you can use it the same way with the
right parser)

