From d03c6f0813ab69460b508049a7ae0e65091a516d Mon Sep 17 00:00:00 2001 From: NuraliyevAzizbek Date: Sun, 3 Nov 2024 18:22:11 +0500 Subject: [PATCH 1/4] lesson in 3.10.2024 6:22 --- python lessons/lerarned_pathlib.py | 34 ++++++++++++++++++++++++++++++ python lessons/question.md | 2 ++ 2 files changed, 36 insertions(+) create mode 100644 python lessons/lerarned_pathlib.py create mode 100644 python lessons/question.md diff --git a/python lessons/lerarned_pathlib.py b/python lessons/lerarned_pathlib.py new file mode 100644 index 0000000..457e495 --- /dev/null +++ b/python lessons/lerarned_pathlib.py @@ -0,0 +1,34 @@ +from pathlib import Path + +#bosh oynaning urlini korsatadi +home_dir = Path.home() +print(home_dir) + +#terminalda turgan joyingizni urlini korsatadi +cwd = Path.cwd() +print(cwd) + +#run bergan file ning urlimi korsatadi +curr_file = Path(__file__) +print(curr_file) + +#shu file dan oldingi urlni korsatadi +one_above = cwd.parent +print(one_above) + +#shu filedan nechtadir oldin fileni urlini korsatadi +move_above = Path.cwd().parents[0] +print(move_above) + +#tanlagan papkani urlini aniqlab beradi +join_path = cwd / 'Geeks' +print(join_path) + +#tanlangan narsa papkaligini tekwirib beradi +print(join_path.is_dir()) + +#tanlangan papkalning ichidagi .py bilan tugediganlarini urllarini aniqlab beradi +target_dir = cwd / 'LevelUp' +for file in target_dir.iterdir(): + if file.suffix == '.py': + print(file) \ No newline at end of file diff --git a/python lessons/question.md b/python lessons/question.md new file mode 100644 index 0000000..4046e3b --- /dev/null +++ b/python lessons/question.md @@ -0,0 +1,2 @@ +- [] dict bilan collections.OrderedDict() ni farqi +- [] \ No newline at end of file From 50f0d4b7387462b6ee5b300739e226574ca9596a Mon Sep 17 00:00:00 2001 From: NuraliyevAzizbek Date: Tue, 5 Nov 2024 02:43:59 +0500 Subject: [PATCH 2/4] homework done --- .../__pycache__/my_logger.cpython-312.pyc | Bin 0 -> 390 bytes python lessons/loggings.py | 64 +++++++++++------- python lessons/question.md | 4 +- 3 files changed, 42 insertions(+), 26 deletions(-) create mode 100644 python lessons/__pycache__/my_logger.cpython-312.pyc diff --git a/python lessons/__pycache__/my_logger.cpython-312.pyc b/python lessons/__pycache__/my_logger.cpython-312.pyc new file mode 100644 index 0000000000000000000000000000000000000000..c36a948c727995e4a08a77faf8b5e35313d2f56b GIT binary patch literal 390 zcmX@j%ge<81dnty)As}E#~=<2utFK1y?~7A3@HpLj5!QZ3``8E3|UMtMF={D2`J8j z;KNuc%xhRyGedZc43&(UtS>}%1tZ*O0fe? zPS4Cszr~%DSe%*coS&DLnSP7a#nma)eI>(ZkQ;tE>SyHVrs^kFWmf6Cq!wqF#H7Ud)sXXyKY91>cfUrw1p9S6b#HJxe`9B1WGVs$ FKLD1;W?ldQ literal 0 HcmV?d00001 diff --git a/python lessons/loggings.py b/python lessons/loggings.py index 746848b..88f9833 100644 --- a/python lessons/loggings.py +++ b/python lessons/loggings.py @@ -1,35 +1,51 @@ from my_logger import logging -# DEBUG -print(logging.DEBUG) # 10 # when you want to know what's going on in your program -# INFO -print(logging.INFO) # 20 # when something expected happens (user logs in) -# WARNING -print( - logging.WARNING -) # 30 # when something unexpected happens (1 000 000$ transaction) -# ERROR -print(logging.ERROR) # 40 # when your program runs into a problem (try/except) -# CRITICAL -print(logging.CRITICAL) # 50 when your program crashes +# # DEBUG +# print(logging.DEBUG) # 10 # when you want to know what's going on in your program +# # INFO +# print(logging.INFO) # 20 # when something expected happens (user logs in) +# # WARNING +# print( +# logging.WARNING +# ) # 30 # when something unexpected happens (1 000 000$ transaction) +# # ERROR +# print(logging.ERROR) # 40 # when your program runs into a problem (try/except) +# # CRITICAL +# print(logging.CRITICAL) # 50 when your program crashes -def error_handling(a: int, b: int): - logging.debug("This is a debug message") - try: - logging.info(f"a is {a}, b is {b}") - div = a / b - logging.info(f"Division is {div}") - return div - except Exception as e: - logging.error(f"Exception occurred: {e}") +# def error_handling(a: int, b: int): +# logging.debug("This is a debug message") +# try: +# logging.info(f"a is {a}, b is {b}") +# div = a / b +# logging.info(f"Division is {div}") +# return div +# except Exception as e: +# logging.error(f"Exception occurred: {e}") +################################################## home work ###################################################### -if __name__ == "__main__": - error_handling(5, 0) +def my_custom_logger(original_func): + def error_func(*args, **kwargs): + logging.debug("ishga tushdi") + try: + print("1") + logging.info(f"o'zgaruvchilar: a = {args[0]}, b = {args[1]}") + new_value = original_func(*args, **kwargs) + logging.info(f"xatoliksiz ishlayabdi") + return new_value + except Exception as e: + logging.warning("xatolik chiqdi") + logging.error(f"Xatolik: {e}") + return error_func -@my_custom_loger # home task +@my_custom_logger # home task def error_handling(a: int, b: int): div = a / b return div + + +if __name__ == "__main__": + error_handling(5, 0) \ No newline at end of file diff --git a/python lessons/question.md b/python lessons/question.md index 4046e3b..34a8116 100644 --- a/python lessons/question.md +++ b/python lessons/question.md @@ -1,2 +1,2 @@ -- [] dict bilan collections.OrderedDict() ni farqi -- [] \ No newline at end of file +- [x] dict bilan collections.OrderedDict() ni farqi +- [] exseption ni nega as e deb ozgartirganimzda chiqyabdi \ No newline at end of file From f91699291b7069b9b4690cdb1ff1e6358f86c81b Mon Sep 17 00:00:00 2001 From: NuraliyevAzizbek Date: Fri, 8 Nov 2024 00:37:44 +0500 Subject: [PATCH 3/4] new --- .gitignore | 1 + .../__pycache__/my_logger.cpython-312.pyc | Bin 390 -> 0 bytes python lessons/loggings.py | 7 ++--- python lessons/question.md | 5 +++- test.log | 27 ++++++++++++++++++ 5 files changed, 35 insertions(+), 5 deletions(-) delete mode 100644 python lessons/__pycache__/my_logger.cpython-312.pyc create mode 100644 test.log diff --git a/.gitignore b/.gitignore index 769e5e2..0bb8010 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ venv/ .DS_Store +__pycache__/ \ No newline at end of file diff --git a/python lessons/__pycache__/my_logger.cpython-312.pyc b/python lessons/__pycache__/my_logger.cpython-312.pyc deleted file mode 100644 index c36a948c727995e4a08a77faf8b5e35313d2f56b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 390 zcmX@j%ge<81dnty)As}E#~=<2utFK1y?~7A3@HpLj5!QZ3``8E3|UMtMF={D2`J8j z;KNuc%xhRyGedZc43&(UtS>}%1tZ*O0fe? zPS4Cszr~%DSe%*coS&DLnSP7a#nma)eI>(ZkQ;tE>SyHVrs^kFWmf6Cq!wqF#H7Ud)sXXyKY91>cfUrw1p9S6b#HJxe`9B1WGVs$ FKLD1;W?ldQ diff --git a/python lessons/loggings.py b/python lessons/loggings.py index 88f9833..e223a8d 100644 --- a/python lessons/loggings.py +++ b/python lessons/loggings.py @@ -28,16 +28,15 @@ def my_custom_logger(original_func): def error_func(*args, **kwargs): - logging.debug("ishga tushdi") + logging.debug(f"ishga tushdi {original_func.__name__}") try: - print("1") logging.info(f"o'zgaruvchilar: a = {args[0]}, b = {args[1]}") new_value = original_func(*args, **kwargs) logging.info(f"xatoliksiz ishlayabdi") return new_value - except Exception as e: + except Exception as a: logging.warning("xatolik chiqdi") - logging.error(f"Xatolik: {e}") + logging.error(f"Xatolik: {a}") return error_func diff --git a/python lessons/question.md b/python lessons/question.md index 34a8116..07e0fcc 100644 --- a/python lessons/question.md +++ b/python lessons/question.md @@ -1,2 +1,5 @@ - [x] dict bilan collections.OrderedDict() ni farqi -- [] exseption ni nega as e deb ozgartirganimzda chiqyabdi \ No newline at end of file +- [] exseption ni nega as e deb ozgartirganimzda chiqyabdi +- [] .gitignore da nimaga venvni oxiriga slew qoyamiz +- [] heroku ni togirlash +- [] \ No newline at end of file diff --git a/test.log b/test.log new file mode 100644 index 0000000..a9eef33 --- /dev/null +++ b/test.log @@ -0,0 +1,27 @@ +2024-11-06 22:38:42,020:DEBUG:ishga tushdi:Line: 31 +2024-11-06 22:38:42,020:INFO:o'zgaruvchilar: a = 5, b = 0:Line: 34 +2024-11-06 22:38:42,020:WARNING:xatolik chiqdi:Line: 39 +2024-11-06 22:38:42,020:ERROR:Xatolik: division by zero:Line: 40 +2024-11-06 22:39:32,933:DEBUG:ishga tushdi:Line: 31 +2024-11-06 22:39:32,933:INFO:o'zgaruvchilar: a = 5, b = 0:Line: 33 +2024-11-06 22:39:32,933:WARNING:xatolik chiqdi:Line: 38 +2024-11-06 22:39:32,933:ERROR:Xatolik: :Line: 39 +2024-11-06 22:39:36,962:DEBUG:ishga tushdi:Line: 31 +2024-11-06 22:39:36,962:INFO:o'zgaruvchilar: a = 5, b = 0:Line: 33 +2024-11-06 22:39:36,962:WARNING:xatolik chiqdi:Line: 38 +2024-11-06 22:39:36,962:ERROR:Xatolik: :Line: 39 +2024-11-06 22:42:27,231:DEBUG:ishga tushdi:Line: 31 +2024-11-06 22:42:27,231:INFO:o'zgaruvchilar: a = 5, b = 0:Line: 33 +2024-11-06 22:42:27,231:WARNING:xatolik chiqdi:Line: 38 +2024-11-06 22:43:07,532:DEBUG:ishga tushdi:Line: 31 +2024-11-06 22:43:07,532:INFO:o'zgaruvchilar: a = 5, b = 0:Line: 33 +2024-11-06 22:43:07,532:WARNING:xatolik chiqdi:Line: 38 +2024-11-06 22:43:07,532:ERROR:Xatolik: division by zero:Line: 39 +2024-11-06 22:44:16,459:DEBUG:ishga tushdi :Line: 31 +2024-11-06 22:44:16,459:INFO:o'zgaruvchilar: a = 5, b = 0:Line: 33 +2024-11-06 22:44:16,459:WARNING:xatolik chiqdi:Line: 38 +2024-11-06 22:44:16,459:ERROR:Xatolik: division by zero:Line: 39 +2024-11-06 22:45:26,172:DEBUG:ishga tushdi error_handling:Line: 31 +2024-11-06 22:45:26,173:INFO:o'zgaruvchilar: a = 5, b = 0:Line: 33 +2024-11-06 22:45:26,173:WARNING:xatolik chiqdi:Line: 38 +2024-11-06 22:45:26,173:ERROR:Xatolik: division by zero:Line: 39 From 492e544f9a0b0cca5048c761c6accce22f9ea358 Mon Sep 17 00:00:00 2001 From: NuraliyevAzizbek Date: Sat, 9 Nov 2024 13:07:20 +0500 Subject: [PATCH 4/4] homework done --- ThreadHomework.py | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 ThreadHomework.py diff --git a/ThreadHomework.py b/ThreadHomework.py new file mode 100644 index 0000000..6de1c6c --- /dev/null +++ b/ThreadHomework.py @@ -0,0 +1,49 @@ +# TASK: Write 10_000_000 line text to a 2 files using threads and GIL in Python +# 1) Create a function that clears the content of a file +# 2) Create a function that writes a text to a file +# 3) Create a function that reads the content of a file +import threading +import time + + +the_word = "qwertyuiopasdfghjklzxcvbnm" +file_name = 'words.txt' + + +def writes(): + with open (file_name, 'a') as file: + for item in range(9_999): + file.write(f"{the_word}\n") + file.write(the_word) + + + +def clears(): + a = 10_000 + while a != 0: + with open (file_name, 'w') as file: + file.writelines(lines[:-1]) + a -= 1 + + +def reads(): + with open (file_name, 'r') as file: + lines = file.readlines() + return len(lines) + + +def main(): + start = time.perf_counter() + t1 = threading.Thread(target=writes(), name="yozuvchi") + t2 = threading.Thread(target=clears(), nmae="tozalovchi") + t1.start() + t2.start() + end = time.perf_counter() + print(t1.getName()) + print(t2.getName()) + print(f"The number of rows remaining {reads()}") + print(f"Time used: {start - end}") + + +if __name__=="__main__": + main() \ No newline at end of file