Characters aren't displayed correctly

John Machin sjmachin at lexicon.net
Mon Mar 2 17:26:57 EST 2009


On Mar 3, 3:27 am, Philip Semanchuk <phi... at semanchuk.com> wrote:
> On Mar 2, 2009, at 10:50 AM, John Machin wrote:
>
> > On Mar 3, 2:22 am, Philip Semanchuk <phi... at semanchuk.com> wrote:
> >> See if you can successfully construct and send an email that says
> >> "Hello world" in English/ASCII. If that works, change it to Arabic.  
> >> If
> >> that works, change the email format to HTML. If that works, starts
> >> pulling the content from the database. If that works, then you're
> >> done. =)
>
> > Yuk. You are asking him to write extra speculative code when he's
> > having extreme difficulty debugging the code he's already got! He's
> > already said he's getting ?????? soon after the database retrieval ---
> > you want him to work on the downstream problem when the upstream is
> > still very muddy???
>
> First of all, I preceded that paragraph with a detailed example of how  
> to verify that he's getting what he expects out of the database. So  
> no, I am not asking the OP to write extra speculative code. I'm giving  
> him another tool with which to work at his problem.
>
> He claims to have done what I asked him to do in the first place --  
> break the problem into steps and verify the database steps. He says  
> they're working OK. I chose to take him at his word.

Rule number 1: Don't believe anything an OP says that is not
corroborated by output that looks like it was produced using the repr
() function (2.x) or ascii() function (3.x)

Rule number 2: Don't ignore rule number 1, especially when not
corroborated by any output at all.

Rule number 3: [added since the Great Renaming aka the Mad Hatter's
Tea Party] Ask the OP what version of Python they are using so that
they can be told to use ascii() instead of repr() if using 3.X

>
> If he's right, then we can move on to the next step of troubleshooting  
> the email. If he's wrong and the problem is indeed with the database  
> code, then we'll eventually discover that

He has *already* demonstrated, at my request, that there is a problem
with, or soon after, the database extraction:

"""
The result of print repr(row['name']) is '??? ??????'
The '?' characters are supposed to be Arabic characters.
"""

> and he'll have learned a  
> valuable lesson. It will be time-consuming and therefore painful for  
> him, but then he'll be more likely to remember it.
>
> There's more than one way to attack this problem/set of problems, yes?
>
> This is all kind of OT since it is about general debugging and not  
> about Python. The only Python-specific aspect I see is that debugging  
> non-ASCII problems with print is a little tricky since it introduces  
> yet another variable -- the terminal's encoding settings. If, for  
> instance, the OP's terminal is set to ISO 8859-6 or some such (I don't  
> know anything about encodings to handle Arabic) and he's feeding it  
> UTF-8, then ??????? might indeed be the result.

and that is the rationale for Rule #1




More information about the Python-list mailing list