python 2.7 - using String.startswith() with a unicode string -
i trying trim string scraped html page using beautifulsoup. starts
 – 
in html page. trying following code:
if thestring.startswith(unichr(160) + '-' + unichr(160)): print "found starting sequence" thestring= thestring[3:]
however, if
condition not being triggered (as confirmed fact print statement not happening). how set condition?
(also in cases, thestring 3 characters, in case want thestring end empty string -- or need separately test case?)
by using thestring.__repr__()
able determine bs giving me string started u'\xa0\u2013\xa0'
then following code works me:
if thestring.startswith(u"\xa0\u2013\xa0"): print "found starting sequence" thestring = thestring[3:]
Comments
Post a Comment