On 11/24/2023 4:49 PM, Rimu Atkinson via Python-list wrote:



I really can't think of a case
where the missing comma would make any sense at all.


That is pretty tricky, yes.

The comma means it's a tuple. Without the comma, it's just a string with parenthesis around it, which is a string.

PyDev console: starting.
Python 3.9.15 (main, Oct 28 2022, 17:28:38) [GCC] on linux
x = ('%' + "2023-11" + '%')
x
'%2023-11%'
x = ('%' +  x + '%',)
x
('%%2023-11%%',)
x.__class__.__name__
'tuple'

To make it very clear in your code so that you are reminded next time you want to re-use it, you could write

param = '%2023-11%'
cr.execute(sql, (param,))

Probably the param value will actually use a variable instead of the hard-coded value in the example. So use an f-string, because it's more readable and easier to get right:

date = ... # Where ever the actual date value comes from
param = f'%{date}%'
cr.execute(sql, (param,))

--
https://mail.python.org/mailman/listinfo/python-list

Reply via email to