Skip to main content

Questions tagged [module]

A logical subdivision of a larger, more complex system.

Filter by
Sorted by
Tagged with
3792 votes
14 answers
2.5m views

What is __init__.py for?

What is __init__.py for in a Python source directory?
Mat's user avatar
  • 85.2k
1260 votes
34 answers
1.9m views

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 준영's user avatar
1123 votes
26 answers
1.2m views

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's user avatar
  • 25.2k
1118 votes
22 answers
945k views

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 ...
Mark Harrison's user avatar
1116 votes
33 answers
1.5m views

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 ...
Ram Rachum's user avatar
899 votes
6 answers
197k views

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 ...
gremo's user avatar
  • 48.3k
850 votes
10 answers
358k views

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's user avatar
  • 9,283
614 votes
22 answers
872k views

How do I find the location of Python module sources? [duplicate]

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, ...
Daryl Spitzer's user avatar
594 votes
21 answers
1.1m views

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 ...
Chris Gow's user avatar
  • 7,754
526 votes
3 answers
551k views

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. ...
Marty Chang's user avatar
  • 6,499
522 votes
11 answers
285k views

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 ...
Owen's user avatar
  • 22.7k
486 votes
8 answers
117k views

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 ...
Gishu's user avatar
  • 136k
466 votes
9 answers
172k views

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 ...
Josh Moore's user avatar
  • 13.4k
449 votes
21 answers
529k views

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(...
Ali's user avatar
  • 10.3k
447 votes
24 answers
1.0m views

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 ...
user1994934's user avatar
  • 4,473
381 votes
6 answers
211k views

What is the purpose of the -m switch?

Could you explain to me what the difference is between calling python -m mymod1 mymod2.py args and python mymod1.py mymod2.py args It seems in both cases mymod1.py is called and sys.argv is ['...
Charles Brunet's user avatar
380 votes
6 answers
597k views

`from ... import` vs `import .` [duplicate]

I'm wondering if there's any difference between the code fragment from urllib import request and the fragment import urllib.request or if they are interchangeable. If they are interchangeable, which ...
wchargin's user avatar
  • 15.9k
361 votes
8 answers
234k views

How to import module when module name has a '-' dash or hyphen in it?

I want to import foo-bar.py, this works: foobar = __import__("foo-bar") This does not: from "foo-bar" import * My question: Is there any way that I can use the above format i.e., ...
Bala's user avatar
  • 4,148
358 votes
17 answers
263k views

How can I conditionally import an ES6 module?

I need to do something like: if (condition) { import something from 'something'; } // ... if (something) { something.doStuff(); } The above code does not compile; it throws SyntaxError: ... '...
ericsoco's user avatar
  • 25.9k
353 votes
27 answers
384k views

I can't install python-ldap

When I run the following command: sudo pip install python-ldap I get this error: In file included from Modules/LDAPObject.c:9: Modules/errors.h:8: fatal error: lber.h: No such file or directory How ...
VacuumTube's user avatar
  • 4,081
339 votes
11 answers
366k views

Defining private module functions in python

According to http://www.faqs.org/docs/diveintopython/fileinfo_private.html: Like most languages, Python has the concept of private elements: Private functions, which can't be called from outside ...
olamundo's user avatar
  • 24.7k
319 votes
2 answers
75k views

What exactly is Hot Module Replacement in Webpack?

I've read a few pages about Hot Module Replacement in Webpack. There's even a sample app that uses it. I've read all of this and still don't get the idea. What can I do with it? Is it supposed to ...
Dan Abramov's user avatar
315 votes
11 answers
406k views

How to import a Python class that is in a directory above?

I want to inherit from a class in a file that lies in a directory above the current one. Is it possible to relatively import that file?
user129975's user avatar
  • 3,555
297 votes
5 answers
389k views

How to create module-wide variables in Python? [duplicate]

Is there a way to set up a global variable inside of a module? When I tried to do it the most obvious way as appears below, the Python interpreter said the variable __DBNAME__ did not exist. ... ...
daveslab's user avatar
  • 10.2k
294 votes
10 answers
228k views

How do I use namespaces with TypeScript external modules?

I have some code: baseTypes.ts export namespace Living.Things { export class Animal { move() { /* ... */ } } export class Plant { photosynthesize() { /* ... */ } } } dog.ts import ...
Ryan Cavanaugh's user avatar
291 votes
1 answer
98k views

Node.js plans to support import/export ES6 (ECMAScript 2015) modules

I've been looking all over the Internet without a clear answer for this. Currently Node.js uses only CommonJS syntax to load modules, and if you really want to use the standard ECMAScript 2015 modules ...
Zorgatone's user avatar
  • 4,264
286 votes
7 answers
188k views

What's the difference between an Angular component and module

I've been watching videos and reading articles but this specific article make me so confused, at the start of the article it says The applications in Angular follow modular structure. The Angular ...
Luis Pena's user avatar
  • 4,314
282 votes
12 answers
288k views

Why is Python running my module when I import it, and how do I stop it?

I have a Python program I'm building that can be run in either of 2 ways: the first is to call python main.py which prompts the user for input in a friendly manner and then runs the user input through ...
Dasmowenator's user avatar
  • 5,793
276 votes
12 answers
142k views

Best way to load module/class from lib folder in Rails 3?

Since the latest Rails 3 release is not auto-loading modules and classes from lib anymore, what would be the best way to load them? From github: A few changes were done in this commit: Do not ...
Vincent's user avatar
  • 16.2k
268 votes
32 answers
603k views

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 ...
user avatar
266 votes
21 answers
370k views

Nodejs cannot find installed module on Windows

I am learning nodejs at the moment on Windows. Several modules are installed globally with npm.cmd, and nodejs failed to find the installed modules. Take jade for example, npm install jade -g Jade ...
Cosmore's user avatar
  • 3,223
264 votes
7 answers
298k views

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 <package name> go build would generate go.mod and go.sum files that contain all found versions for the package ...
dimus's user avatar
  • 9,072
259 votes
6 answers
343k views

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

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 ...
lmiguelvargasf's user avatar
248 votes
36 answers
292k views

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 >...
user1161310's user avatar
  • 3,139
247 votes
24 answers
388k views

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?
242 votes
13 answers
384k views

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 ...
pafcu's user avatar
  • 8,038
234 votes
16 answers
172k views

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 ...
Runcible's user avatar
  • 3,088
228 votes
2 answers
210k views

What to put in a python module docstring? [closed]

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 ...
user avatar
220 votes
7 answers
237k views

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 ...
vimfluencer's user avatar
  • 3,166
218 votes
14 answers
291k views

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 ...
Claus's user avatar
  • 4,519
218 votes
5 answers
127k views

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] // ...
user's user avatar
  • 5,290
215 votes
11 answers
171k views

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 ...
Orion Edwards's user avatar
209 votes
28 answers
277k views

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 ...
Fearghal's user avatar
  • 11.1k
207 votes
3 answers
186k views

Execution of Python code with -m option or not [duplicate]

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 ...
prosseek's user avatar
  • 188k
207 votes
15 answers
537k views

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/...
user avatar
203 votes
3 answers
102k views

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 ...
Vlad the Impala's user avatar
201 votes
7 answers
116k views

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. ...
MaTHwoG's user avatar
  • 2,041
194 votes
6 answers
160k views

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's user avatar
193 votes
16 answers
507k views

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: ...
Philipp_Kats's user avatar
  • 4,132
191 votes
4 answers
144k views

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 ...
Andrei Vajna II's user avatar

1
2 3 4 5
456