Liberal Arts

  • Friday, March 11, 2016

    Python Source Code To Get The Names Of Unicode Characters

     
    #!/usr/bin/python3 
     
    """This is an example script of the unicodedata module in use.""" 
     
    import unicodedata  
    
    
     
    numbers = []
    
    for i in range(300):
    
        numbers.append(i)
    
     
    
    characters = []
    
    for i in range(300):
    
        characters.append(chr(i))
    
     
    
    adam = dict(zip(numbers, characters))
    
     
    
    def getNames():
    
        hum = 0
    
        for i in adam.values():
    
            try:
    
                print (unicodedata.name(i) + " is \
    the name of number {}.".format(hum))
    
                hum += 1
    
            except:
    
                print ("Unknown name for character \
    number {}.".format(hum))
    
                hum += 1
    
     
    
    if __name__ == "__main__":
    
        try:
    
            getNames()
    
        except:
    
            print ("This should never have to be printed \
    because the function works.")
    
        finally:
    
            print("There you have it. Hail and farewell.")