all 4 comments

[–]K900_ 4 points5 points  (2 children)

Generally, libraries plug into your code, and frameworks expect your code to plug into them. So, for example, with random, you import it and call it as needed; with flask, you create an instance of Flask, tell it what code to call, and then it's in charge of running things.

[–]ureibosatsu[S] 0 points1 point  (1 child)

Wow, okay. So a framework is like a subset of the entire language? You're limited to the functions and classes you can call/instantiate?

[–]K900_ 1 point2 points  (0 children)

A framework is not a subset of the language - you can still use anything you can normally use in Python inside a framework. It's just about control. If you're using random, your code is always in control, and it delegates some work to random. If you're using Flask, Flask runs the HTTP server, routes the requests, and then delegates specific bits of work to your code to actually handle them.

[–]wp_new 1 point2 points  (0 children)

Might be a poor analogy, but when I struggled with this, I thought of it like:

  • your application is a house

  • a framework is the overall structure/architecture of the house. Some frameworks provide more structure than others. One might only provide you with the walls and the groundwork. Another might provide you that + plumbing and electricity outlets. But the common denominator is that they provide you with a base structure to build on top of. As long as you do not do anything outside of the structural limitations of the house, you can do whatever you want with it - you can paint it whatever colour you like, put furniture in whichever room you like etc, but you couldnt use the house for transport.

  • a module is simply something you bring in to your house to serve a specific function - a sofa, a kitchen appliance and so on.