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
130
votes
7 answers

In Python, can I call the main() of an imported module?

In Python I have a module myModule.py where I define a few functions and a main(), which takes a few command line arguments. I usually call this main() from a bash script. Now, I would like to put everything into a small package, so I thought that…
Ricky Robinson
  • 21,798
  • 42
  • 129
  • 185
129
votes
12 answers

How to make a cross-module variable?

The __debug__ variable is handy in part because it affects every module. If I want to create another variable that works the same way, how would I do it? The variable (let's be original and call it 'foo') doesn't have to be truly global, in the…
Dan Homerick
  • 4,118
  • 7
  • 28
  • 30
127
votes
4 answers

Create module variables in Ruby

Is there any way to create a variable in a module in Ruby that would behave similar to a class variable? What I mean by this is that it would be able to be accessed without initializing an instance of the module, but it can be changed (unlike…
Mark Szymanski
  • 56,590
  • 24
  • 70
  • 87
127
votes
13 answers

What is the most compatible way to install python modules on a Mac?

I'm starting to learn python and loving it. I work on a Mac mainly as well as Linux. I'm finding that on Linux (Ubuntu 9.04 mostly) when I install a python module using apt-get it works fine. I can import it with no trouble. On the Mac, I'm used to…
GloryFish
  • 13,078
  • 16
  • 53
  • 43
126
votes
4 answers

Whats the difference between a module and a library in Python?

I have background in Java and I am new to Python. I want to make sure I understand correctly Python terminology before I go ahead. My understanding of a module is: a script which can be imported by many scripts, to make reading easier. Just like in…
joker
  • 1,995
  • 3
  • 15
  • 17
125
votes
3 answers

Python: importing a sub‑package or sub‑module

Having already use flat packages, I was not expecting the issue I encountered with nested packages. Here is… Directory layout dir | +-- test.py | +-- package | +-- __init__.py | +-- subpackage | +--…
Hibou57
  • 6,870
  • 6
  • 52
  • 56
120
votes
1 answer

Do I need to use the "import type" feature of TypeScript 3.8 if all of my imports are from my own file?

I have a simple file types.ts that defines some types: export interface MyInterface { // ... } export const enum MyEnum { // ... } export type MyType = { // ... } I have read about the new feature import type for the latest typescript…
Ilya Chernomordik
  • 27,817
  • 27
  • 121
  • 207
119
votes
2 answers

What is mattr_accessor in a Rails module?

I couldn't really find this in Rails documentation but it seems like 'mattr_accessor' is the Module corollary for 'attr_accessor' (getter & setter) in a normal Ruby class. Eg. in a class class User attr_accessor :name def set_fullname @name…
JasonOng
  • 3,268
  • 3
  • 21
  • 17
119
votes
3 answers

How to import a module in Python with importlib.import_module

I'm trying to use importlib.import_module in Python 2.7.2 and run into the strange error. Consider the following dir structure: a | + - __init__.py - b | + - __init__.py - c.py a/b/__init__.py has the…
Zaar Hai
  • 9,152
  • 8
  • 37
  • 45
117
votes
3 answers

Target a css class inside another css class

Hi I am having problems with some css classes in joomla. I have two divs in a module, one is the wrapper class="wrapper", the other is the content class="content" . Content is inside wrapper. What I am trying to do is target a css style on the…
Iain Simpson
  • 8,011
  • 13
  • 47
  • 66
115
votes
4 answers

Python: import module from another directory at the same level in project hierarchy

I've seen all sorts of examples and other similar questions, but I can't seem to find an example that exactly matches my scenario. I feel like a total goon asking this because there are so many similar questions, but I just can't seem to get this…
CptSupermrkt
  • 6,844
  • 12
  • 56
  • 87
114
votes
23 answers

ImportError: No module named tensorflow

Please help me with this error I have installed the tensorflow module on my server and below is it's information 15IT60R19@cpusrv-gpu-109:~$ pip show tensorflow Name: tensorflow Version: 1.0.0 Summary: TensorFlow helps the tensors flow Home-page:…
Abhishek Gangwar
  • 1,697
  • 3
  • 17
  • 29
113
votes
4 answers

C++ Modules - why were they removed from C++0x? Will they be back later on?

I just discovered this old C++0x draft about modules in C++0x. The idea was to get out of the current .h/.cpp system by writing only .cpp files which would then generate module files during compilation, which would then in turn be used by the other…
Tomaka17
  • 4,832
  • 5
  • 29
  • 38
108
votes
6 answers

ansible : how to pass multiple commands

I tried this: - command: ./configure chdir=/src/package/ - command: /usr/bin/make chdir=/src/package/ - command: /usr/bin/make install chdir=/src/package/ which works, but I was hoping for something neater. So I tried this: from:…
John Doe
  • 1,570
  • 3
  • 13
  • 22
108
votes
1 answer

Haskell export current module with additional imported module

Is it possible to write a module in Haskell, which re-exports a module in addition to exporting everything visible inside? Lets consider following module: module Test where import A f x = x This module exports everything defined inside, so it…
Wojciech Danilo
  • 11,573
  • 17
  • 66
  • 132