Was ist das da in meinem Dictionary?

Wenn du dir nicht sicher bist, in welchem der anderen Foren du die Frage stellen sollst, dann bist du hier im Forum für allgemeine Fragen sicher richtig.
Antworten
MKK
User
Beiträge: 10
Registriert: Dienstag 19. April 2005, 11:38
Kontaktdaten:

Hi!
Was machen dise "u" plötzlich in meinem Dictionary??

a.getvalue() liefert:

Code: Alles auswählen

a {
    text-decoration: underline;
    font-size: 10px;
    }

okay, nun der Code:

Code: Alles auswählen

a=StringIO.StringIO(cssParse(css)) 
for line in a:
  handleLine(line) #Handles CSS 
okay, nun die funktionen

Code: Alles auswählen

cssDict = {}
filename=""
inner = 0  # true when handling a tag
currtag='' # name of current tag
attrs = '' # list of names within current tag
def handleLine(l):
  global inner, currtag , attrs	
  l = l.split()
  if ('{' in l): # from now on "within '{' brackets"
    inner=1
    currtag = l[0]
    attrs = ""
  elif ('}' in l):  # "leaving the '{}' brackets"
    inner=0
    addToDict(cssDict,currtag,attrs)
    currtag=''
  elif (inner==1):
    attrs = attrs+" ".join(l)
   
def addToDict(dict, name, format): #dict=Dictionary, name=CSS Identifier, format=CSS Formatinfo
  dict.setdefault(name, format)
print cssDict liefert

Code: Alles auswählen

{u'a': u'text-decoration: underline;font-size: 10px;'}
WTF machen diese komischen "u" in meinem Dictionary????
Leonidas
Python-Forum Veteran
Beiträge: 16025
Registriert: Freitag 20. Juni 2003, 16:30
Kontaktdaten:

Das heißt einfach nur, dass die Strings in Unicode sind.

Code: Alles auswählen

>>> s = "Leonidas"
>>> u = u"Leonidas"
>>> type(s)
>>> type(u)
>>> su = str(u)
>>> type(su)
Mehr Infos zu diesem (komplexen) Thema gibt es in den exzellenten Python Unicode FAQ.
My god, it's full of CARs! | Leonidasvoice vs (former) Modvoice
Antworten