8000 Add section 6 project, to test out absolute and relative imports. · songsaks/complete-python-course@56c3570 · GitHub
[go: up one dir, main page]

Skip to content

Commit 56c3570

Browse files
committed
Add section 6 project, to test out absolute and relative imports.
1 parent 01c87ae commit 56c3570

File tree

7 files changed

+31
-0
lines changed

7 files changed

+31
-0
lines changed

section6/imports_project/app.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from utils import utils
2+
from utils.common.file_operations import save_to_file, read_file
3+
4+
save_to_file('Hello, world!', 'test.txt')
5+
print(read_file('test.txt'))
6+
7+
print(f'app is {__name__}')

section6/imports_project/test.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Hello, world!

section6/imports_project/utils/__init__.py

Whitespace-only changes.

section6/imports_project/utils/common/__init__.py

Whitespace-only changes.
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
from ..json_operations import dict_to_json
2+
3+
4+
def save_to_file(content, filename):
5+
with open(filename, 'w') as file:
6+
file.write(content)
7+
8+
9+
def read_file(filename):
10+
with open(filename, 'r') as file:
11+
return file.read()
12+
13+
print(f'file_operations is {__name__}')#
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
import json
2+
3+
4+
def dict_to_json(d):
5+
return json.dumps(d)
6+
7+
print(f'json_operations is {__name__}')
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
from .common.file_operations import save_to_file
2+
3+
print(f'utils is {__name__}')

0 commit comments

Comments
 (0)
0