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

Can you define aliases for imported modules in Python?

In Python, is it possible to define an alias for an imported module? For instance: import a_ridiculously_long_module_name ...so that is has an alias of 'short_name'.
Jordan Parmer
  • 36,042
  • 30
  • 97
  • 119
188
votes
6 answers

module is not defined and process is not defined in eslint in visual studio code

I have installed eslint in my machine and i have used visual studio code i have certain modules and process to be exported When i try to use "module" or "process" it shows it was working fine before. [eslint] 'module' is not defined.…
MaTHwoG
  • 1,911
  • 2
  • 7
  • 11
188
votes
5 answers

How do I use a macro across module files?

I have two modules in separate files within the same crate, where the crate has macro_rules enabled. I want to use the macros defined in one module in another module. // macros.rs #[macro_export] // or not? is ineffectual for this,…
user
  • 4,920
  • 3
  • 25
  • 38
183
votes
9 answers

Pass options to ES6 module imports

Is it possible to pass options to ES6 imports? How do you translate this: var x = require('module')(someoptions); to ES6?
Fabrizio Giordano
  • 2,941
  • 4
  • 20
  • 16
183
votes
4 answers

Can I use __init__.py to define global variables?

I want to define a constant that should be available in all of the submodules of a package. I've thought that the best place would be in in the __init__.py file of the root package. But I don't know how to do this. Suppose I have a few subpackages…
Andrei Vajna II
  • 4,642
  • 5
  • 35
  • 38
182
votes
10 answers

Angular 8 - Lazy loading modules : Error TS1323: Dynamic import is only supported when '--module' flag is 'commonjs' or 'esNext'

When I updated Angular from 7 to Angular 8, getting error for lazy loading modules I have tried the options, which are there in the angular upgradation guide Made the below changes: Before loadChildren: '../feature/path/sample- …
RajuPedda
  • 3,141
  • 3
  • 14
  • 27
174
votes
16 answers

Python can't find module in the same folder

My python somehow can't find any modules in the same directory. What am I doing wrong? (python2.7) So I have one directory '2014_07_13_test', with two files in it: test.py hello.py where hello.py: # !/usr/local/bin/python # -*- coding: utf-8…
Philipp_Kats
  • 3,872
  • 3
  • 27
  • 44
167
votes
4 answers

How do I call setattr() on the current module?

What do I pass as the first parameter "object" to the function setattr(object, name, value), to set variables on the current module? For example: setattr(object, "SOME_CONSTANT", 42); giving the same effect as: SOME_CONSTANT = 42 within the module…
Matt Joiner
  • 112,946
  • 110
  • 377
  • 526
166
votes
12 answers

Where are the python modules stored?

I have recently started learning Python and I have 2 questions relating to modules. Is there a way to obtain a list of Python modules available (i.e. installed) on a machine? I am using Ubuntu Karmic and Synaptic for package management. I have just…
morpheous
  • 16,270
  • 32
  • 89
  • 120
161
votes
7 answers

Bypass confirmation prompt for pip uninstall

I'm trying to uninstall all django packages in my superuser environment to ensure that all my webapp dependencies are installed to my virtualenv. sudo su sudo pip freeze | grep -E '^django-' | xargs pip -q uninstall But pip wants to confirm every…
hobs
  • 18,473
  • 10
  • 83
  • 106
160
votes
4 answers

Rust modules confusion when there is main.rs and lib.rs

I have 4 files: main.rs mod bar; fn main() { let v = vec![1, 2, 3]; println!("Hello, world!"); } lib.rs pub mod foo; pub mod bar; foo.rs pub fn say_foo() { } bar.rs use crate::foo; fn bar() { foo::say_foo(); } When I run cargo…
nz_21
  • 6,140
  • 7
  • 34
  • 80
158
votes
10 answers

ES6 export all values from object

Say I have a module (./my-module.js) that has an object which should be its return value: let values = { a: 1, b: 2, c: 3 } // "export values" results in SyntaxError: Unexpected token So I can import them like: import {a} from './my-module' …
mauvm
  • 3,586
  • 3
  • 18
  • 19
155
votes
4 answers

How to change a module variable from another module?

Suppose I have a package named bar, and it contains bar.py: a = None def foobar(): print a and __init__.py: from bar import a, foobar Then I execute this script: import bar print bar.a bar.a = 1 print bar.a bar.foobar() Here's what I…
shino
  • 4,562
  • 5
  • 38
  • 57
152
votes
9 answers

How to properly export an ES6 class in Node 4?

I defined a class in a module: "use strict"; var AspectTypeModule = function() {}; module.exports = AspectTypeModule; var AspectType = class AspectType { // ... }; module.export.AspectType = AspectType; But I get the following error…
Jérôme Verstrynge
  • 57,710
  • 92
  • 283
  • 453
152
votes
2 answers

Why does Typescript use the keyword "export" to make classes and interfaces public?

While dabbling with Typescript I realised my classes within modules (used as namespaces) were not available to other classes unless I wrote the export keyword before them, such as: module some.namespace.here { export class SomeClass{..} } So now…
Grofit
  • 17,693
  • 24
  • 96
  • 176