Questions tagged [module]

A logical subdivision of a larger, more complex system.

Modules are a convenient way to break down a larger problem and divide it into smaller problems/solutions. This way the main problem can be broken down into separate parts that can be worked on independently. For example, one module could consist of a the printing functionality of program, which can be handed to one programmer. The GUI (Graphical User Interface) could be another module, handed to another programmer, and so forth.

Modular design is meant to improve efficiency and speed of development by allowing programmers to work on specific aspects of the program independently of each other.

22551 questions
3611
votes
14 answers

What is __init__.py for?

What is __init__.py for in a Python source directory?
Mat
  • 82,161
  • 34
  • 89
  • 109
1219
votes
33 answers

How do I get a list of locally installed Python modules?

How do I get a list of Python modules installed on my computer?
Léo Léopold Hertz 준영
  • 134,464
  • 179
  • 445
  • 697
1081
votes
22 answers

How do I unload (reload) a Python module?

I have a long-running Python server and would like to be able to upgrade a service without restarting the server. What's the best way do do this? if foo.py has changed: unimport foo <-- How do I do this? import foo myfoo = foo.Foo()
Mark Harrison
  • 297,451
  • 125
  • 333
  • 465
1081
votes
26 answers

How to retrieve a module's path?

I want to detect whether module has changed. Now, using inotify is simple, you just need to know the directory you want to get notifications from. How do I retrieve a module's path in python?
Cheery
  • 24,645
  • 16
  • 59
  • 83
1069
votes
32 answers

Importing modules from parent folder

I am running Python 2.5. This is my folder tree: ptdraft/ nib.py simulations/ life/ life.py (I also have __init__.py in each folder, omitted here for readability) How do I import the nib module from inside the life module? I am hoping…
Ram Rachum
  • 84,019
  • 84
  • 236
  • 374
899
votes
6 answers

Relation between CommonJS, AMD and RequireJS?

I'm still very confused about CommonJS, AMD and RequireJS, even after reading a lot. I know that CommonJS (formerly ServerJS) is a group for defining some JavaScript specifications (i.e. modules) when the language is used outside the browser.…
gremo
  • 47,186
  • 75
  • 257
  • 421
827
votes
10 answers

What's the difference between a module and package in Python?

What's the difference between a module and package in Python? See also: What's the difference between "package" and "module"? (for other languages)
Dave
  • 9,033
  • 4
  • 21
  • 20
598
votes
20 answers

How do I find the location of Python module sources?

How do I learn where the source file for a given Python module is installed? Is the method different on Windows than on Linux? I'm trying to look for the source of the datetime module in particular, but I'm interested in a more general answer as…
Daryl Spitzer
  • 143,156
  • 76
  • 154
  • 173
578
votes
20 answers

How to list all functions in a module?

I have a Python module installed on my system and I'd like to be able to see what functions/classes/methods are available in it. I want to call the help function on each one. In Ruby I can do something like ClassName.methods to get a list of all the…
Chris Gow
  • 7,514
  • 4
  • 23
  • 18
519
votes
11 answers

What is the difference between include and require in Ruby?

My question is similar to "What is the difference between include and extend in Ruby?". What's the difference between require and include in Ruby? If I just want to use the methods from a module in my class, should I require it or include it?
Owen
  • 22,247
  • 13
  • 42
  • 47
513
votes
3 answers

module.exports vs. export default in Node.js and ES6

What is the difference between Node's module.exports and ES6's export default? I'm trying to figure out why I get the "__ is not a constructor" error when I try to export default in Node.js 6.2.2. What works 'use strict' class SlimShady { …
Marty Chang
  • 6,269
  • 5
  • 16
  • 25
480
votes
7 answers

What is the difference between include and extend in Ruby?

Just getting my head around Ruby metaprogramming. The mixin/modules always manage to confuse me. include: mixes in specified module methods as instance methods in the target class extend: mixes in specified module methods as class methods in the…
Gishu
  • 134,492
  • 47
  • 225
  • 308
462
votes
9 answers

Difference between a class and a module

I came from Java, and now I am working more with Ruby. One language feature I am not familiar with is the module. I am wondering what exactly is a module and when do you use one, and why use a module over a class?
Josh Moore
  • 13,338
  • 15
  • 58
  • 74
432
votes
21 answers

Declare multiple module.exports in Node.js

What I'm trying to achieve is to create one module that contains multiple functions in it. module.js: module.exports = function(firstParam) { console.log("You did it"); }, module.exports = function(secondParam) { console.log("Yes you did it"); },…
Ali
  • 9,997
  • 20
  • 70
  • 105
432
votes
24 answers

Python 3: ImportError "No Module named Setuptools"

I'm having troubles with installing packages in Python 3. I have always installed packages with setup.py install. But now, when I try to install the ansicolors package I get: importerror "No Module named Setuptools" I have no idea what to do…
user1994934
  • 4,323
  • 2
  • 14
  • 8
1
2 3
99 100