Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# This is a basic workflow to help you get started with Actions

name: CI

on: push

jobs:
code_quality:
runs-on: ubuntu-latest
name: Checks with black, isort and possibly run tests
container: python:3.9

steps:
- name: Checkout code
uses: actions/checkout@v2
- name: Run script
run: |
pip install flake8 isort pytest
ls -la
flake8 .
isort --check .
py.test tests
132 changes: 0 additions & 132 deletions homework1/.gitignore

This file was deleted.

2 changes: 0 additions & 2 deletions homework1/requirements.txt

This file was deleted.

2 changes: 0 additions & 2 deletions homework1/sample_project/calculator/calc.py

This file was deleted.

2 changes: 0 additions & 2 deletions homework1/sample_project/requirements.txt

This file was deleted.

Empty file.
15 changes: 0 additions & 15 deletions homework1/sample_project/tests/test_calculator.py

This file was deleted.

Empty file removed homework1/tasks/__init__.py
Empty file.
11 changes: 0 additions & 11 deletions homework1/tasks/task02.py

This file was deleted.

17 changes: 0 additions & 17 deletions homework1/tasks/task03.py

This file was deleted.

10 changes: 0 additions & 10 deletions homework1/tasks/task04.py

This file was deleted.

11 changes: 0 additions & 11 deletions homework1/tasks/task05.py

This file was deleted.

Empty file removed homework1/tests/__init__.py
Empty file.
10 changes: 0 additions & 10 deletions homework1/tests/some_file.txt

This file was deleted.

49 changes: 0 additions & 49 deletions homework1/tests/tests.py

This file was deleted.

File renamed without changes.
52 changes: 52 additions & 0 deletions homework8/task01.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
"""
We have a file that works as key-value storage, each line is represented
as key and value separated by = symbol, example:

name=kek
last_name=top
song_name=shadilay
power=9001

Values can be strings or integer numbers.
If a value can be treated both as a number and a string,
it is treated as number.

Write a wrapper class for this key value storage that works like this:

storage = KeyValueStorage('path_to_file.txt')
that has its keys and values accessible
as collection items and as attributes.
Example:
storage['name'] # will be string 'kek'
storage.song_name # will be 'shadilay'
storage.power # will be integer 9001

In case of attribute clash existing built-in attributes take precedence.
In case when value cannot be assigned to an attribute
(for example when there's a line 1=something) ValueError should be raised.
File size is expected to be small,
you are permitted to read it entirely into memory.

"""

from keyword import iskeyword


class KeyValueStorage:
def __init__(self, filename):
self.storage = {}
with open(filename) as f:
text = f.read()
key_value = [x.split("=") for x in text.split()]
for key, value in key_value:
if iskeyword(key) or not key.isidentifier():
raise ValueError("Invalid key!")
if value.isdigit():
value = int(value)
self.storage[key] = value

def __getitem__(self, key):
return self.storage[key]

def __getattr__(self, key):
return self.storage[key]
Loading