String substitution VS proper mysql escaping

Stefan Schwarzer sschwarzer at sschwarzer.net
Thu Aug 19 13:41:11 CEST 2010


Hi Νίκος,

On 2010-08-19 09:10, Νίκος wrote:
> On 18 Αύγ, 12:50, Cameron Simpson <c... at zip.com.au> wrote:
>>
>> ("nikos",) is a single element tuple.
>> ["nikos"] is a single element list.
>> ["nikos",] is also a single element list, just written like the tuple.
> 
> It makes more sense if i:
> 
> "nikos" is just a string
> ("nikos") is a single element tuple
> ["nikos"] is also a single element list
> 
> After all () used to define tuples and [] usedd to define lists. Why
> commas?

Because parentheses are also used to group expressions.
For example,

>>> 2 * (1+2)
6

If it were as you would like, the result would have been

(3, 3)

So because <something_without_commas> inside parentheses
already denotes an expression you have to add a comma to
distinguish a one-element tuple from an expression.

Stefan



More information about the Python-list mailing list