[Tutor] SQLite3 DB Field Alphabetizing

David Hutto smokefloat at gmail.com
Wed Oct 13 15:13:50 CEST 2010

On Wed, Oct 13, 2010 at 8:17 AM, Joel Goldstick
<joel.goldstick at gmail.com> wrote:
> On Wed, Oct 13, 2010 at 4:01 AM, Alan Gauld <alan.gauld at btinternet.com>
> wrote:
>> "David Hutto" <smokefloat at gmail.com> wrote
>>> Below is the output before converting:
>>> [(u'.hjvkjgfkj/bdgfkjbg', u''), (u'bbbbbbbbbbbbuuzzzzzzzzz', u'Pie
>>> Chart'), (u'jgkgyckghc', u''), (u'kfhhv ', u''), (u'khfhf', u''),
>>> (u'test', u''), (u'test10', u''), (u'test2', u'Dashed/Dotted'),
>>> (u'test3', u'Pie Chart'), (u'test346w43', u''), (u'test4', u'Scatter
>>> Plot'), (u'test5', u''), (u'test6', u''), (u'test7', u''),
>>> (u'test7uyuy', u''), (u'test8', u''), (u'test9', u''), (u'testgraph',
>>> u''), (u'u;s;juf;sfkh', u''), (u'zzrerhshhjrs', u'')]
>> And there is the answer to your question.
>> The string that you thought started with ; actually starts with a 'u'
>> But you strip the 'u;' off that entry so it appears to be badly ordered.
>> So the next question is why do you strip the 'u' off?
>> I suspect the answer to that also lies here.
>> I suspect you think you need to strip all the 'u's from the front of
>> these results but in fact those 'u's lie outside the string, they
>> are a part of Python's representation of a unicode string,
>> not a part of the string.
>> So if you remove the call to strip() your code will return
>> the result you expected.
>> --
>> Alan Gauld
>> Author of the Learn to Program web site
>> http://www.alan-g.me.uk/
> Not to belabor the point too much, I plucked one of your strings out and
> printed it.  Looking at your data, all those u' prefixes you thought you
> were removing were (in a sense) never really there!  The only u you removed
> was the one near the end that was followed with a semicolon.

I see it now. I knew that the u outside ' ' is the coding for the
string, but I thought I had to strip it before using it since that was
how it showed up. The bug of course would be that graphs that start
with u would go to the second letter, but the u would still be used in
alphabetization, because the alphabetizing is prior to stripping.

Thanks, for the help with that.
> print u'zzrerhshhjrs'
> zzrerhshhjrs
> --
> Joel Goldstick
> _______________________________________________
> Tutor maillist  -  Tutor at python.org
> To unsubscribe or change subscription options:
> http://mail.python.org/mailman/listinfo/tutor

More information about the Tutor mailing list