9

There are 22 questions and growing on [python] file TypeError: expected a string or other character buffer object, which you get whenever you try file.write() for anything other than a string: a list, list of strings, mixed list of numbers and strings, list-of-lists, any other arbitrary data structure... But canonically the same thing.

The answer is always that you have to convert the answer into one or more strings or separate lines each being a string. Or just ' '.join(...) So the answer varies slightly depending on the input.

How should we canonicalize them? Which one(s) should be canonical? Most have bad titles, and many don't have very general answers (the tagging and titling for SEO can be improved). I don't think we need 22 badly-named questions.

Click through and go read the list of 22, it's not very stellar and none of them stands out.

1
  • 9
    You might want to pop in the Python chatroom who maintain a list of canonical questions and have written a few self-answered community wikis for some of the more common ones.
    – Jon Clements Mod
    Commented Dec 16, 2017 at 12:35

1 Answer 1

3

Without looking to your specific example(s) (as I'm not really a expert):

How should we canonicalize them?

The best way to approach canonicals still is to provide a self answered question (make it community wiki if you want to ensure being not accused to do that plagiarizing and only doing that for the rep).

We can duplicate mark older questions for better newer ones, and that could be an approach to tidy this up.

Which one(s) should be canonical?

As mentioned above rather start your own.

It's hard to tell, which questions with correct and good generalized answers would be chosen as canonical duplicates over the time. But obviously the oldest mentions of the problem have the best chances.

Also some questions are that basic, that they aren't considered to be useful at all, and the asker is rather expected to read the relevant language documentation, than asking a question at Stack Overflow.

These are likely to get deleted over time anyways.

12
  • Hmm. One of that list of 22 can presumably be improved, but after looking through it for 15 min my head hurts. But still I think one of them can be elevated to canonical. But please take a look at those specific Q&A.
    – smci
    Commented Dec 16, 2017 at 12:30
  • @smci "But please take a look at those specific Q&A." As I mentioned, I'm not a python expert, and that wouldn't help much actually. I'm trying to answer your concerns more generally. The best canonicals I've ever seen at SO were specifically designed for that pupose.
    – user0042
    Commented Dec 16, 2017 at 12:33
  • I know that, my question is more "Is anything in this list of dreck salvageable and capable of being elevated into canonical?" It may well be the case that it isn't, and it's community wiki time. Either way, I want people to pause and reflect on why we are constantly writing bad ad-hoc answers to non-generalizable questions with crappy tagging, even worse titles, and non-reproducible code. Clogging up the site such that a search doesn't return one clear answer way on top. There Must Be A Better Way To Do It.
    – smci
    Commented Dec 16, 2017 at 12:37
  • @smci "on why we are constantly writing bad ad-hoc answers to non-generalizable questions with crappy tagging, even worse titles, and non-reproducible code" That happens in the c++ tag realm all the time, and I'm happy to close vote that stuff for the primary reasons. If you're a dupe-hammer holder in python, take care not to abuse it in pointing to poor and crappy "canonicals" just for closure.
    – user0042
    Commented Dec 16, 2017 at 12:41
  • @smci Here's a brand new example of that silliy behavior you describe though.
    – user0042
    Commented Dec 16, 2017 at 12:48
  • Uhuh. I'm trying to keep this discussion firmly focused on Python file-writing of objects (wrt list of specific Q&A I gave), and not on a general philosophical debate on non-generalizable questions... Closing dupes without also collectively striving to create high-quality generalized answers is just treading water. Writing a Python object to a file is so incredibly basic. I really want to understand why after 15 years its treatment on SO is so deficient.
    – smci
    Commented Dec 16, 2017 at 13:04
  • 1
    @smci the clue might be in your wording: Writing a Python object to a file is so incredibly basic... Either the questions that pop up have circumstances which are unique and can't be generalised or no one's thought people would have issues with it and thus haven't gone out of their way and written a canonical post...
    – Jon Clements Mod
    Commented Dec 16, 2017 at 13:08
  • @JonClements: no, the circumstances aren't unique. If you skim through that list of 22, the use cases are pretty basic. I genuinely believe I've found a hole which is badly-served for no particular reason, but on this topic people have gotten into the habit of answering a non-generalized question with a non-canonical answer.
    – smci
    Commented Dec 16, 2017 at 13:11
  • @smci I don't think my answer gives too general advice for your situation. I you really found that hole that needs a fixture, fix it. If it's all so basic with those questions, it shouldn't be too hard to summarize them up in a canonical Q&A.
    – user0042
    Commented Dec 16, 2017 at 13:16
  • 3
    "But obviously the oldest mentions of the problem have the best chances." It doesn't always work that way in Python, though. There are some important differences between Python 2 & Python 3, particularly in the handling of text vs bytes (and that obviously impacts file handling). Python 3 is almost 10 years old, but it took a few years to gain traction, and there's still a lot of Python 2 code being used. Most of the old Python code on SO is Python 2, but we are trying to strongly promote the use of Python 3 on SO because Python 2 will reach its official End of Life in 2020.
    – PM 2Ring
    Commented Dec 16, 2017 at 14:14
  • @PM2Ring: making Python3 content, esp. canonicals, supersede Python2, is worthy of attention, as long as the Python 2 stuff can still be found with tag python-2.x. But all these people blindly splatting + operators on lists of objects and object slices are all using Python 2 and copying code examples (mostly bad or badly-explained ones)
    – smci
    Commented Dec 19, 2017 at 2:53
  • "These are likely to get deleted over time anyways." Asking nearly 5 years later: by what process? I looked again just now and the results still seem pretty bad. E.g. stackoverflow.com/questions/40948108 is a pure debugging question with no debugging effort, completely unsearchable... and has survived the entire time, reaching +5. If properly MREd and retitled, it might be something like "Why can't I .replace part of my string with an integer?". Also, 2.x EOLd more than 2 years ago, and I am still editing old canonicals that aren't 2.x-specific to add parens to print calls. Commented Jul 1, 2022 at 21:10

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .