python 2.7.12 on Linux behaving differently than on Windows

Steven D'Aprano steve+comp.lang.python at pearwood.info
Mon Dec 5 03:33:09 EST 2016


On Monday 05 December 2016 17:20, DFS wrote:

>>> Edit: I got it to work this way:
>>> column2="'R'"
>>>
>>> but that's bogus, and I don't want users to have to do that.
>>
>> (1) It's not bogus.
> 
> 
> It's extremely bogus.  It's discarding part of my input.

When you type 

name = 'Fred'

do you expect that the first character of the variable name is a quotation 
mark? No? Then why is it okay for Python to discard the quotation mark but not 
bash or some other shell?

Shells don't just repeat the characters you type, they interpret them. 
Characters like $ & * ? [ ] { } and others have special meaning to the shell, 
as do quotation marks.


[...]
>> (3) If my interpretation is correct, what *is* bogus is that that your
>> column names include quotes in them.
> 
> 
> Of course not.  I'm not sure I've ever seen quotes or apostrophes in a
> column name.

*shrug* It would be a pretty crazy thing to do, and I'm very glad to hear that 
my wild guess as to what was going on was wrong.

> And that's a pretty crazy interpretation that nothing in my post would
> lead you to.

That's the curse of knowledge speaking: you're familiar enough with SQL that 
you can no longer remember what it was like to be unfamiliar with it.

I'm not familiar with SQL syntax, and to me, the fact that SQL was complaining 
when the quotation marks were missing from the column name suggested to me that 
the quotes were part of the name. To me, the analogy that came to my mind was 
the similar-looking error in the shell:


steve at runes:~$ ls "'foo'"
'foo'
steve at runes:~$ ls 'foo'
ls: cannot access foo: No such file or directory

The quotation marks are part of the filename, and so they need to be protected 
from the shell or else you get an error quite similar to the one you got:

    no such column: R


but there is (or so it appeared) a column 'R' (hence it looks like the quotes 
are part of the column name).

Anyway, I'm glad you have a solution that satisfies you.



-- 
Steven
"Ever since I learned about confirmation bias, I've been seeing 
it everywhere." - Jon Ronson




More information about the Python-list mailing list