Loading environment modules within a python script

I know this question’s kind of old but it’s still relevant enough that I was looking for the answer, so I’m posting what I found that works as well: At least in the 3.2.9+ sources, you can include the python “init” file to get a python function version of module: >>> exec(open(‘/usr/local/Modules/default/init/python.py’).read()) >>> module(‘list’) No … Read more

addr2line on kernel module

I suppose the module is built with debug info included. If so, you can use gdb or objdump to find out which source file and line each address belongs to. Something like this: $ gdb “$(modinfo -n my_module)” (gdb) list *(some_function+0x12c) Gdb will now tell the name of the source file and the line in … Read more

Python modules with submodules and functions

A folder with .py files and a __init__.py is called a package. One of those files containing classes and functions is a module. Folder nesting can give you subpackages. So for example if I had the following structure: mypackage __init__.py module_a.py module_b.py mysubpackage __init__.py module_c.py module_d.py I could import mypackage.module_a or mypackage.mysubpackage.module_c and so on. … Read more

ES6 module scope

Can I use “a” variable in a global scope after module importing or is it available only in a module scope? It’s only available inside the module it was declared in. Will ES6 modules have a similar working principle like this trick: […] Basically yes. ES6 has these kinds of scopes, order from “top” to … Read more

Overriding method by another defined in module

In Ruby 2.0 and later you can use Module#prepend: class Date prepend DateExtension end Original answer for older Ruby versions is below. The problem with include (as shown in the following diagram) is that methods of a class cannot be overridden by modules included in that class (solutions follow the diagram): Solutions Subclass Date just … Read more

Multiple Module in Angularjs

Yes, you can define multiple modules in angularJS as given below. var myApp = angular.module(‘myApp’, []) var myApp2 = angular.module(‘myApp2′, []) However, don’t forget to define the dependency during each module declarations as below. Let’s assume myApp2 dependent on myApp. Hence, the declaration would be something similar to, var myApp = angular.module(‘myApp’, []) var myApp2 … Read more

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

All of your top level module declarations should go in main.rs, like so: mod mod1; mod mod2; fn main() { println!(“Hello, world!”); mod1::mod1fn(); } You can then use crate::mod2 inside mod1: use crate::mod2; pub fn mod1fn() { println!(“1”); mod2::mod2fn(); } I’d recommend reading the chapter on modules in the new version of the Rust book … Read more