I really can't think of a case
where the missing comma would make any sense at all.
This is driving me crazy, I'm running this code:-
cr.execute(sql, ('%' + "2023-11" + '%'))
I have to say this seems very non-pythonesque to me, the 'obvious'
default simply doesn't work right, and I really can't think of a case
where the missing comma would make any sense at all.
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.
Chris Green <cl@isbd.net> writes:
I have to say this seems very non-pythonesque to me, the 'obvious'
default simply doesn't work right, and I really can't think of a case
where the missing comma would make any sense at all.
|6.15 Expression lists
...
|an expression list containing at least one comma yields a tuple.
...
The Python Language Reference, Release 3.13.0a0;
Guido van Rossum and the Python development team;
October 10, 2023.
Chris Green <cl@isbd.net> wrote:
This is driving me crazy, I'm running this code:-
OK, I've found what's wrong:-
cr.execute(sql, ('%' + "2023-11" + '%'))
should be:-
cr.execute(sql, ('%' + x + '%',) )
I have to say this seems very non-pythonesque to me, the 'obvious'
default simply doesn't work right, and I really can't think of a case
where the missing comma would make any sense at all.
The error message could be a bit more helpful too, maybe one of those|(1, 2, 3)
"... did you mean ....?" ones could point one in the right direction.
a = 1, 2, 3
print( a )
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'
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 452 |
Nodes: | 16 (0 / 16) |
Uptime: | 99:15:18 |
Calls: | 9,273 |
Calls today: | 6 |
Files: | 13,511 |
Messages: | 6,070,185 |
Posted today: | 1 |