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
62
votes
4 answers

How do I automatically install missing python modules?

I would like to be able to write: try: import foo except ImportError: install_the_module("foo") What is the recommended/idiomatic way to handle this scenario? I've seen a lot of scripts simply print an error or warning notifying the user…
j b
  • 5,147
  • 5
  • 41
  • 60
62
votes
5 answers

Python: import the containing package

In a module residing inside a package, i have the need to use a function defined within the __init__.py of that package. how can i import the package within the module that resides within the package, so i can use that function? Importing __init__…
guy
62
votes
16 answers

Angular2 lazy loading module error 'cannot find module'

I was trying to find any solution for this error but nothing works for me. I have simple Angular2 App created with Angular-CLI. When I serve this app in browser I'm getting this error: EXCEPTION: Uncaught (in promise): Error: Cannot find module…
arthurr
  • 1,135
  • 1
  • 10
  • 19
62
votes
10 answers

How can I find out where a Perl module is installed?

How do get the path of a installed Perl module by name, e.g. Time::HiRes? I want this just because I have to run my perl script on different nodes of a SGE Grid Engine system. Sometimes, even run as other username. I can use CPAN.pm to install…
Galaxy
  • 1,862
  • 1
  • 17
  • 25
61
votes
2 answers

How does Python importing exactly work?

I have two specific situations where I don't understand how importing works in Python: 1st specific situation: When I import the same module in two different Python scripts, the module isn't imported twice, right? The first time Python encounters…
corazza
  • 31,222
  • 37
  • 115
  • 186
60
votes
3 answers

How to include files from same directory in a module using Cargo/Rust?

I have a Cargo project consisting of three files in the same directory: main.rs, mod1.rs and mod2.rs. I want to import functions from mod2.rs to mod1.rs the same way I would import functions from mod1.rs to main.rs. I've read about the file…
Neo
  • 3,534
  • 2
  • 20
  • 32
60
votes
7 answers

How to fix this ES6 module circular dependency?

EDIT: for more background, also see the discussion on ES Discuss. I have three modules A, B, and C. A and B import the default export from module C, and module C imports the default from both A and B. However, module C does not depend on the values…
trusktr
  • 44,284
  • 53
  • 191
  • 263
60
votes
3 answers

Organizing Python classes in modules and/or packages

I like the Java convention of having one public class per file, even if there are sometimes good reasons to put more than one public class into a single file. In my case I have alternative implementations of the same interface. But if I would place…
deamon
  • 89,107
  • 111
  • 320
  • 448
60
votes
8 answers

How can I require an optional Perl module if installed?

I have Perl code which relies on Term::ReadKey to get the terminal width. My installation is missing this module, so I want to provide a default if the module isn't present rather than throw an exception. How can I conditionally use an optional…
dlamblin
  • 43,965
  • 20
  • 101
  • 140
60
votes
3 answers

What is the intention of Ninject modules?

I'm a complete newbie to ninject I've been pulling apart someone else's code and found several instances of nInject modules - classes that derive from Ninject.Modules.Module, and have a load method that contains most of their code. These classes are…
Jonathan
  • 32,202
  • 38
  • 137
  • 208
60
votes
4 answers

What happens when a module is imported twice?

I have a doubt that I would like to get cleared up. Consider the following module named ex_1.py: print("Hello, I'm ex_1") def greet(name): print("Hello, "+name+" nice to meet you! ") Now consider another file called 1_client_ex_1.py that will…
Shonu93
  • 846
  • 1
  • 10
  • 19
60
votes
6 answers

improving speed of Python module import

The question of how to speed up importing of Python modules has been asked previously (Speeding up the python "import" loader and Python -- Speed Up Imports?) but without specific examples and has not yielded accepted solutions. I will therefore…
RAAC
  • 961
  • 2
  • 9
  • 11
59
votes
3 answers

Error handling when importing modules

This probably has an obvious answer, but I'm a beginner. I've got a "module" (really just a file with a bunch of functions I often use) at the beginning of which I import a number of other modules. Because I work on many systems, however, not all…
Dave Schultz
  • 591
  • 1
  • 4
  • 3
59
votes
15 answers

Python pip install module is not found. How to link python to pip location?

I'm a newbie and I needed the pySerial and feedparser module for my projects. I'm running Mountain lion. I followed the following tutorial so that I could upgrade to python 2.7.3 and then use the above mentioned…
user1953478
  • 705
  • 1
  • 5
  • 8
58
votes
4 answers

What is a module in .NET?

What exactly is a module? What is the difference between a module, a class and a function? How can I access a module in C#? I am asking this because I want to calculate a checksum of the IL code of only some particular functions, at runtime (without…
Pushkar
  • 1,300
  • 2
  • 15
  • 20