Desidero essere in grado di aggiungere una "u" a una variabile stringa referenziata. Ho bisogno di fare questo perché quando sono in un ciclo for, posso accedere alla stringa solo da un nome di variabile.Come aggiungere un carattere unicode prima di una stringa? [Python]
C'è un modo per farlo?
>>> word = 'blahblah'
>>> list = ['blahblah', 'boy', 'cool']
>>> import marisa_trie
>>> trie = marisa_trie.Trie(list)
>>> word in trie
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Argument 'key' has incorrect type (expected unicode, got str)
>>> 'blahblah' in trie
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: Argument 'key' has incorrect type (expected unicode, got str)
>>> u'blahblah' in trie
True
>>> u"blahblah" in trie
True
>>> u(word) in trie
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'u' is not defined
>>> uword in trie
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'uword' is not defined
>>> u+word in trie
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'u' is not defined
>>> word.u in trie
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'str' object has no attribute 'u'
La funzione Unicode funziona! Grazie – Tai