error when trying to keep order of dictonary as it was found
Question: I want the dictionary to be kept in the same order that the dates are found so
the dictionary is order by date. I looked at [this python
site](http://docs.python.org/2/library/collections.html#collections.OrderedDict)
but the code does not work I get and error when trying to use this class. Any
ideas why and how I can fix it?

    
    
    page = str('<OPTION VALUE="08/25/2013" >08/25/2013</OPTION><OPTIONVALUE="09/01/2013">09/01/2013</OPTION><OPTION VALUE="09/08/2013" >09/08/2013</OPTION><OPTION VALUE="09/15/2013" >09/15/2013</OPTION><OPTION VALUE="09/22/2013" >09/22/2013</OPTION><OPTION VALUE="09/29/2013" >09/29/2013</OPTION><OPTION VALUE="10/06/2013" >10/06/2013</OPTION><OPTION VALUE="10/13/2013" >10/13/2013</OPTION><OPTION VALUE="10/20/2013">10/20/2013</OPTION><OPTIONVALUE="10/27/2013">10/27/2013</OPTION><OPTION VALUE="11/03/2013" >11/03/2013</OPTION><OPTION VALUE="11/10/2013" >11/10/2013</OPTION><OPTION VALUE="11/17/2013" >11/17/2013</OPTION><OPTION VALUE="11/24/2013" >11/24/2013</OPTION><OPTION VALUE="12/01/2013" >12/01/2013</OPTION><OPTION VALUE="12/08/2013" >12/08/2013</OPTION><OPTION VALUE="12/15/2013" >12/15/2013</OPTION>OPTION VALUE="12/22/2013" >12/22/2013</OPTION><OPTION VALUE="12/29/2013" >12/29/2013</OPTION><OPTION VALUE="01/05/2014" >01/05/2014</OPTION><OPTION VALUE="01/12/2014" >01/12/2014</OPTION><OPTION VALUE="01/19/2014" >01/19/2014</OPTION><OPTION VALUE="01/26/2014" >01/26/2014</OPTION><OPTION VALUE="02/02/2014" >02/02/2014</OPTION><OPTION VALUE="02/09/2014" >02/09/2014</OPTION><OPTION VALUE="02/16/2014" >02/16/2014</OPTION><OPTION VALUE="02/23/2014" >02/23/2014</OPTION><OPTION VALUE="03/02/2014" >03/02/2014</OPTION><OPTION VALUE="03/09/2014" >03/09/2014</OPTION><OPTION VALUE="03/16/2014" >03/16/2014</OPTION><OPTION VALUE="03/23/2014" >03/23/2014</OPTION><OPTION VALUE="03/30/2014" >03/30/2014</OPTION><OPTION VALUE="04/06/2014" >04/06/2014</OPTION><OPTION VALUE="04/13/2014" >04/13/2014</OPTION><OPTION VALUE="04/20/2014" >04/20/2014</OPTION><OPTION VALUE="04/27/2014" >04/27/2014</OPTION><OPTION VALUE="05/04/2014" >05/04/2014</OPTION><OPTION VALUE="05/11/2014" >05/11/2014</OPTION><OPTION VALUE="05/18/2014" >05/18/2014</OPTION><OPTION VALUE="05/25/2014" >05/25/2014</OPTION><OPTION VALUE="06/01/2014" >06/01/2014</OPTION><OPTION VALUE="06/08/2014" >06/08/2014</OPTION><OPTION VALUE="06/15/2014" >06/15/2014</OPTION>')
    
    
    def web_link (enter_web_link):
    #11%2F10%2F2013
        enter_web_link =  enter_web_link.replace("/","%") #00%00%0000
        add_twoF = enter_web_link[:3]+"2F"+ enter_web_link[3:]  #00%2F00%0000
        add_twoF_everywhere = add_twoF[:8] +"2F"+add_twoF[8:]
        add_twoF_everywhere = str(add_twoF_everywhere)
        return  add_twoF_everywhere
    
    def search_13(page):
        starter = '<OPTION VALUE="' # find the postion where this starts
        start_link = page.find(starter)
        starter = len(starter)
        if start_link == -1:
            return None, 0, None 
        start_link = start_link + starter
        end_date = start_link + 10
        datetext  = page[start_link: end_date]
        str_date = str(datetext) #this is hte actuall normal looking date dd/mm/yyyy
        enter_web_link = str_date # this will enter we_link function to change to percent signs
        endoflinkdate = web_link(enter_web_link)
        return str_date , end_date,  endoflinkdate
    
    
    def getalllinks(page):
        links = {}  
        while True:
            str_date,end_date,endoflinkdate = search_13(page)
            if str_date:
                links[str_date] ='link' +  endoflinkdate
                page = page[end_date:]
            else:
                break
        return links
    
    
    
    work = getalllinks(page)
    print work
    
    class OrderedCounter(Counter, OrderedDict):  #THIS DOES NOT WORK CAUSES ERRORS 
        def __repr__(self):
            return '%s(%r)' % (self.__class__.__name__, OrderedDict(self))
        def __reduce__(self):
            return self.__class__, (OrderedDict(self),)
    var1 = OrderedCounter(page,links)
    print var1 
    

error:

    
    
     Traceback (most recent call last):
          File "schedule.py", line 43, in <module>
            class OrderedCounter(Counter, OrderedDict):
        NameError: name 'Counter' is not defined
    

how is it not defined its a parameter?

I want this as a dictionary as {date:link, date:link} I can get this but it is
not in the same order of the dates in variable page. I want the order to be
the same as the dates are found in variable page so 08/25/2013: link,
09/01/2013:link,

I want to keep it in a dictionary because I paste it in a javascript website
so I can enter a date and get the link and also have an ordered scroll down
menu.


Answer: If you want to use things from Python libraries, you need to import the
library first:

    
    
    from collections import OrderedDict, Counter
    

