Seite 1 von 1
Hex Notation in String ablegen
Verfasst: Montag 14. Mai 2012, 16:10
von hypnoticum
Hallo,
ich versuche gerade '\x0a' in einem String zu speichern und bekomme immmer '\n' heraus. warum ist das so bzw gibt es ein Gegenmittel?
Danke
Re: Hex Notation in String ablegen
Verfasst: Montag 14. Mai 2012, 16:16
von jens
Re: Hex Notation in String ablegen
Verfasst: Montag 14. Mai 2012, 16:20
von hypnoticum
tut mir leid, das habe ich schon ausprobiert. In Idle sieht das bei mir dann so aus:
IDLE 2.6.5
>>> a = '\\x0a'
>>> a
'\\x0a'
Re: Hex Notation in String ablegen
Verfasst: Montag 14. Mai 2012, 16:30
von cofi
Code: Alles auswählen
In [1]: a = '\\x0a'
In [2]: a
Out[2]: '\\x0a'
In [3]: print a
\x0a
[2] ist das Ergebnis von `repr(a)` [3] das von `str(a)`. Die `repr` Ausgabe hat dabei dir Bedeutung "wenn ich eval darauf anwende, dann bekomme ich so ein Objekt wieder heraus", daher der Unterschied.
Re: Hex Notation in String ablegen
Verfasst: Montag 14. Mai 2012, 16:34
von hypnoticum
danke !!
Re: Hex Notation in String ablegen
Verfasst: Montag 14. Mai 2012, 16:46
von BlackJack
@hypnoticum: Nur für den Fall, dass Du ein Byte mit dem Dezimalwert 10 speichern wolltest: