[Tutor] string codes

spir denis.spir at gmail.com
Tue Nov 26 10:19:46 CET 2013


Hello,

I am coming back to Python after quite a long time, have forgotten everything, 
and don't know anything of python 3. I use python 3.3 for its nice unicode text 
type.

=== codes ===

What is the method to get a code or list of codes inside a string:
	s = "abcde"
	c = s.code(2)
	assert(c == 0x63)
?

=== sub compare ===

Is there a method to compare a substring, without building a substring from the 
big one? Like startswith or endswith, but anywhere inside the string?
	test = s[1, -1] == "bcd"	# no!, builds a substring
	test = s.sub_is(1, -1, "bcd")	# yes! what I'm searching

If this method does not exist, what do you think of it? (Well, the name is not 
great, but could not find better ;-)

Thank you,
Denis


More information about the Tutor mailing list