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
258
votes
6 answers

ModuleNotFoundError: What does it mean __main__ is not a package?

I am trying to run a module from the console. The structure of my directory is this: I am trying to run the module p_03_using_bisection_search.py, from the problem_set_02 directory using: $ python3 p_03_using_bisection_search.py The code inside…
lmiguelvargasf
  • 63,191
  • 45
  • 217
  • 228
244
votes
6 answers

How to point Go module dependency in go.mod to a latest commit in a repo?

Starting with v1.11 Go added support for modules. Commands go mod init go build would generate go.mod and go.sum files that contain all found versions for the package dependencies. If a module does not have any releases, the latest…
dimus
  • 8,712
  • 10
  • 45
  • 56
243
votes
36 answers

Android Studio: Module won't show up in "Edit Configuration"

I've imported a project to Android Studio with several subprojects. I want to run a subproject. I successfully made this subproject's build.gradle as a module. In order to run it, I went to Run > edit configurations > + > Android Application.…
user1161310
  • 3,069
  • 3
  • 21
  • 27
238
votes
32 answers

Typescript ReferenceError: exports is not defined

Trying to implement a module following the official handbook, I get this error message: Uncaught ReferenceError: exports is not defined at app.js:2 But nowhere in my code do I ever use the name exports. How can I fix this? Files app.ts let a =…
George C.
  • 6,574
  • 12
  • 55
  • 80
236
votes
24 answers

What's the easiest way to install a missing Perl module?

I get this error: Can't locate Foo.pm in @INC Is there an easier way to install it than downloading, untarring, making, etc?
dreeves
  • 26,430
  • 45
  • 154
  • 229
233
votes
13 answers

Generate random numbers with a given (numerical) distribution

I have a file with some probabilities for different values e.g.: 1 0.1 2 0.05 3 0.05 4 0.2 5 0.4 6 0.2 I would like to generate random numbers using this distribution. Does an existing module that handles this exist? It's fairly simple to code on…
pafcu
  • 7,808
  • 12
  • 42
  • 55
226
votes
16 answers

How to deal with cyclic dependencies in Node.js

I've been working with nodejs lately and still getting to grips with the module system, so apologies if this is an obvious question. I want code roughly like the below: a.js (the main file run with node) var ClassB = require("./b"); var ClassA =…
Runcible
  • 3,008
  • 3
  • 19
  • 19
225
votes
2 answers

What to put in a python module docstring?

Ok, so I've read both PEP 8 and PEP 257, and I've written lots of docstrings for functions and classes, but I'm a little unsure about what should go in a module docstring. I figured, at a minimum, it should document the functions and classes that…
user297250
217
votes
7 answers

Export multiple classes in ES6 modules

I'm trying to create a module that exports multiple ES6 classes. Let's say I have the following directory structure: my/ └── module/ ├── Foo.js ├── Bar.js └── index.js Foo.js and Bar.js each export a default ES6 class: // Foo.js export…
vimfluencer
  • 3,106
  • 3
  • 17
  • 25
214
votes
11 answers

Can I invoke an instance method on a Ruby module without including it?

Background: I have a module which declares a number of instance methods module UsefulThings def get_file; ... def delete_file; ... def format_text(x); ... end And I want to call some of these methods from within a class. How you normally do…
Orion Edwards
  • 121,657
  • 64
  • 239
  • 328
211
votes
17 answers

PyCharm error: 'No Module' when trying to import own module (python script)

I have written a module (a file my_mod.py file residing in the folder my_module). Currently, I am working in the file cool_script.py that resides in the folder cur_proj. I have opened the folder in PyCharm using File -- open (and I assume, hence, it…
Claus
  • 4,409
  • 4
  • 19
  • 16
202
votes
3 answers

What does a . in an import statement in Python mean?

I'm looking over the code for Python's multiprocessing module, and it contains this line: from ._multiprocessing import win32, Connection, PipeConnection instead of from _multiprocessing import win32, Connection, PipeConnection the subtle…
Vlad the Impala
  • 15,572
  • 16
  • 81
  • 124
199
votes
15 answers

Can't import my own modules in Python

I'm having a hard time understanding how module importing works in Python (I've never done it in any other language before either). Let's say I have: myapp/__init__.py myapp/myapp/myapp.py myapp/myapp/SomeObject.py myapp/tests/TestCase.py Now I'm…
user623990
192
votes
3 answers

Execution of Python code with -m option or not

The python interpreter has -m module option that "Runs library module module as a script". With this python code a.py: if __name__ == "__main__": print __package__ print __name__ I tested python -m a to get "" <-- Empty…
prosseek
  • 182,215
  • 215
  • 566
  • 871
191
votes
26 answers

Android Studio Run/Debug configuration error: Module not specified

I am getting a 'Module not specified' error in my run config. I have no module showing in the drop down yet I can see my module no probs. The issue came about when I refactored my module name, changed the settings.gradle to new name. Now when I go…
Fearghal
  • 10,569
  • 17
  • 55
  • 97