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/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 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/loggings.py b/python lessons/loggings.py index 746848b..e223a8d 100644 --- a/python lessons/loggings.py +++ b/python lessons/loggings.py @@ -1,35 +1,50 @@ 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(f"ishga tushdi {original_func.__name__}") + try: + 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 a: + logging.warning("xatolik chiqdi") + logging.error(f"Xatolik: {a}") + 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 new file mode 100644 index 0000000..07e0fcc --- /dev/null +++ b/python lessons/question.md @@ -0,0 +1,5 @@ +- [x] dict bilan collections.OrderedDict() ni farqi +- [] 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