Skip to content

Commit 5a3b597

Browse files
committed
code for 0x12 modules
1 parent ae62640 commit 5a3b597

File tree

11 files changed

+71
-0
lines changed

11 files changed

+71
-0
lines changed

12_modules/python/foo/__init__.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
from .other import otherstuff
2+
3+
4+
def bar():
5+
print("bar")
6+
otherstuff()
339 Bytes
Binary file not shown.
285 Bytes
Binary file not shown.

12_modules/python/foo/other.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
def otherstuff():
2+
print("otherstuff")

12_modules/python/main.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import foo
2+
3+
if __name__ == "__main__":
4+
print("main")
5+
foo.bar()
6+
foo.otherstuff()

12_modules/python/modules.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import sys as mysys
2+
from os import path as p, system
3+
import os
4+
5+
# inline module not possible
6+
7+
if __name__ == "__main__":
8+
os.path.isfile("/etc/hosts")
9+
p.isdir("/etc/hosts")
10+
system("ls")
11+
mysys.exit(1)

12_modules/rust/foo.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
mod other;
2+
3+
pub use self::other::otherstuff;
4+
pub fn bar() {
5+
dbg!("bar");
6+
otherstuff();
7+
}

12_modules/rust/foo/other.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
pub fn otherstuff() {
2+
dbg!("otherstuff");
3+
}

12_modules/rust/main.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
mod foo; // this loads the file foo.rs
2+
3+
fn main() {
4+
dbg!("main");
5+
foo::bar();
6+
foo::otherstuff();
7+
//foo::other::otherstuff();
8+
}

12_modules/rust/modules.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
use std::io as sio;
2+
use std::rc::{Rc as RefCounted, Weak};
3+
4+
mod foo {
5+
pub fn bar() {}
6+
}
7+
8+
fn main() -> sio::Result<()> {
9+
let x = RefCounted::new(std::i32::MAX);
10+
let _y: Weak<i32> = RefCounted::downgrade(&x);
11+
foo::bar();
12+
Ok(())
13+
}

0 commit comments

Comments
 (0)