Alex Hall wrote:
> I've also had to special case strings when dealing with iterables
> generically, and it's annoying, but it's not a big deal. The real problem
> is when you meant to pass an iterable of strings and you just passed a
> single string and it produces confusing behaviour - something more subtle
> than each character being laid out separately. And even this is not that
> hard for experienced devs like us to figure out, but it really bites
> beginners hard, and I think that's the argument worth focusing on.
> A common example is when beginners write code like this:
> cursor.execute('INSERT INTO strings VALUES (?)', 'hello')
> 
> and get this confusing error:
> sqlite3.ProgrammingError: Incorrect number of bindings supplied. The
> current statement uses 1, and there are 5 supplied.
> Finding questions about these is pretty easy, below are some examples:
> https://stackoverflow.com/questions/54856759/sqlite3-programmingerror-incorr...
> https://stackoverflow.com/questions/16856647/sqlite3-programmingerror-incorr...
> https://stackoverflow.com/questions/6066681/python-sql-select-statement-from...
> https://stackoverflow.com/questions/33768447/incorrect-number-of-bindings-su...
> https://stackoverflow.com/questions/35560106/incorrect-number-of-bindings-su...
> https://stackoverflow.com/questions/58786727/incorrect-number-of-bindings-su...
> So first of all, I think we should probably have a check in the sqlite3
> library for passing a single string as a parameter.
> But in the general case, it would be great if strings weren't iterable and
> trying to iterate over them raised an exception with a helpful generic
> message, like:
> "Strings are not iterable - you cannot loop over them or treat them as a
> collection. Perhaps you meant to use string.chars(), string.split(), or
> string.splitlines()?"

`(3)` and `(3,)` are not the same and I think there is nothing wrong with 
literal integers.

A library implemented in a confusing way is not an example of nothing wrong on 
Python strings. (I myself has made this stupid mistake many times and I cannot 
blame neither Python nor sqlite for being careless.)

In my humble opinion, your example does not prove that iterable strings are 
faulty. They can be tricky in some occasions, I admit it... but there are many 
tricks in all programming languages especially for newbies (currently I am 
trying to learn Lisp... again).
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/74NAU7D5T4HYYXTE7LFYGZPBYB44F3KJ/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to