65

In a comment on a Stack Overflow answer to my question, somebody said that "it is a very 'batteries not included' approach":

it doesn't look like there's any easy way to make a strict RFC 4627-compliant parser using just the builtin modules. In principle you could write your own parser (perhaps using Lex/Yacc/Flex/Bison), but that's a very "batteries not included" approach (and I'm not even sure how those tools integrate with Python, if at all).

I searched its meaning but ended up finding that the phrase was the name of a movie and a book. I would like to know what it means in the context and how it is often used. Many Thanks.

12
  • 25
    It is just a metaphor (fairly common on Stack Overflow, in my experience) that means something is not an out-of-box solution, not ready-to-go, will require tweaking, and probably involves some degree of hassle. Henry's answer provides the correct etymology. I've used this before myself, and never considered that its meaning might not be obvious to non-native speakers! Apr 17, 2017 at 12:06
  • 3
    Of course, the existence of a movie and book by that name do make things a little more confusing.
    – Zibbobz
    Apr 17, 2017 at 16:30
  • 4
    @CodyGray Related to "... is left as an exercise for the reader." Apr 17, 2017 at 17:44
  • 9
    Also related to "some assembly required", implying that the product requires the user to complete a (sometimes substantial) amount of work to make the product functional.
    – asgallant
    Apr 17, 2017 at 18:08
  • 2
    This is not a generic metaphor, but a common Python software term. (I almost thought that quote had come from me, because I have written similar Python software answers on SO)
    – smci
    Apr 18, 2017 at 10:01

3 Answers 3

117

"Batteries not included" is a message you might find on the packaging of an electrically powered toy. Essentially it means that you should not expect the toy to work straight out of the box, and that you have to provide an essential component yourself to power it, namely the batteries.

So in this metaphorical context, the comment seems to be suggesting Python's json module does not provide the parser you are looking for, and you might have to put in a significant amount of extra effort yourself to provide what is missing, so as to get the whole thing to work as you expect.

7
  • 57
    In particular, Python advertises itself as "batteries included" thanks to its comprehensive standard library. There is even a chapter in the docs with that title. That paragraph even specifically calls out the json module as an example, the very module that the question is about. Apr 17, 2017 at 12:23
  • 3
    @JörgWMittag - I suppose the whole situation with Python may seem ironic, but in this particular case (regarding json), I believe the Stack Overflow comment misrepresented the effort required. OP needs to write either zero or two additional lines of Python code to make it work for them. I will say that some other Python "batteries" are arguably on the skimpy side. Regardless, this answer certainly gets the English right and explains it well.
    – John Y
    Apr 17, 2017 at 14:06
  • 1
    @JohnY Supplying your own batteries is not a lot of work, so "batteries not included" is a good metaphor when you only have to do a small amount of additional work.
    – Barmar
    Apr 17, 2017 at 16:11
  • 7
    One other bit of context since this is ELL-- the "batteries not included" often leads to much disappointment when you find the package that should do what you want, then you find out that it is missing some essential components to make it work. Just as a child is disappointed when he gets his much desired toy, only to find out "batteries not included" means he has to wait until after Christmas when the stores open to buy batteries. (though this is less of a problem today with rechargeable toys, retailers pushing batteries at the checkout lanes, and many retailers having Christmas hours)
    – Johnny
    Apr 17, 2017 at 18:01
  • 6
    @Barmar - If you want to look at it that way, you are missing the aspects of the metaphor which are relevant to the context in which it is used. In programming, the batteries you need may or may not exist at all. You might not be able to go to a store to buy them; you might have to build them yourself, which is why Henry (and the Stack Overflow commenter) brought up the "significant extra effort". In OP's case, if we want to stick with this metaphor, Python's library does have the battery they need, they just have to bend the contact slightly to be more snug to the battery terminal.
    – John Y
    Apr 17, 2017 at 19:02
19

This is a reference to Python's batteries included philosophy.

The Python source distribution has long maintained the philosophy of "batteries included" -- having a rich and versatile standard library which is immediately available, without making the user download separate packages. This gives the Python language a head start in many projects.

The manual has a section with the same title but that's a poor explanation.

The original quote is much better understood in a "batteries included, this solution is not" way because what it suggests is not adding a battery, much rather powering it via a generator attached to a standing bike so to speak. In other words, the other upvoted answer might be correct in the general sense to explain the generic "batteries not included" phrase but it has nothing to do with the problem at hand.

In this case, it means you would be using the "raw" features of the language and not components already written by others. As another example, you can download a webpage by opening a socket to the relevant IP address port 80, create a request based on the HTTP standard and correctly interpret the response, follow redirect(s) etc. That's the "powered through your own sweat" solution. Or

import requests
requests.get('https://english.stackexchange.com/a/384948/8720')

would be a "batteries included" kind of solution (even if actually requests is not included in the standard library but it serves as a quick demo).

2
  • 1
    I like that this answer provides another perspective and more carefully addresses the specific instance that motivated OP. The example using a "battery" that doesn't come with the standard library is especially illuminating. If I had to pick one "right" answer, it would be the other one, in large part because it is the more accurate answer to the general question reflected in the subject line, and thus is probably more helpful to more people finding this question in a search. But nice job, and easily worth an upvote from me.
    – John Y
    Apr 19, 2017 at 13:28
  • 2
    The term "batteries included" has also spread from Python to other projects. The OCaml Batteries Included documentation (scroll to the bottom of the page) attributes their use of the term back to Python, and also mentions a similar project for Haskell.
    – DaoWen
    Apr 19, 2017 at 16:48
2

The saying, as I've often seen it used is, describes something that doesn't include everything it needs to function. Much like its usage on toy or other electronics packaging, the item (the toy or such) requires you to create or acquire something (i.e. batteries), because that sub-component is distributed separately.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.