On Wed, 24 May 2023 at 08:22, Rob Cliffe <rob.cli...@btinternet.com> wrote: > > > > This sort of code might be better as a single expression. For example: > > > > user = ( > > request.GET["user"] > > .decode("utf-8") > > .strip() > > .lower() > > ) > > user = orm.user.get(name=user) > > > > > LOL. And I thought I was the one with a (self-confessed) tendency to > write too slick, dense, smart-alec code. 😁 > Indeed, I was itching to shorten it (starting with the low-hanging > fruit: user = user.strip().lower() ). > Seriously though: this kind of condensation can come unstuck when any of > the steps need to be made more complicated. > (Suppose request.GET might return ASCII, might return Unicode, depending > on which server it was talking to.)
Do you mean "ASCII or UTF-8"? Because decoding as UTF-8 is fine with ASCII (it's a superset). You should always consistently get the same data type (bytes or text) based on the library you're using. ChrisA -- https://mail.python.org/mailman/listinfo/python-list