Method which converts the object instance and its attributes to a string of lilypond code

        :return: str of lilypond code

def toLily(self):
        '''
        Method which converts the object instance and its attributes to a string of lilypond code

        :return: str of lilypond code
        '''

        lilystring = ""
        if hasattr(self, "size"):
            try:
                size = float(self.size)
                lilystring += "\\abs-fontsize #" + str(self.size) + " "
            except:
                lilystring += "\\" + str(self.size) + " "
        if hasattr(self, "font"):
            fonts_available = ["sans", "typewriter", "roman"]
            if self.font in fonts_available:
                lilystring += "\\" + self.font + " "
            else:
                rand = random.Random()
                selected = rand.choice(fonts_available)
                lilystring += "\\" + selected + " "
        valid = False
        for char in self.text:
            if char in string.ascii_letters or char in [
                    "0",
                    "1",
                    "2",
                    "3",
                    "4",
                    "5",
                    "6",
                    "7",
                    "8",
                    "9"]:
                if not hasattr(self, "noquotes"):
                    lilystring += "\""
                lilystring += self.text
                if not hasattr(self, "noquotes"):
                    lilystring += "\" "
                valid = True
                break
            else:
                valid = False
        if not valid:
            lilystring = ""
        return lilystring