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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
venv/
.DS_Store
__pycache__/
49 changes: 49 additions & 0 deletions ThreadHomework.py
Original file line number Diff line number Diff line change
@@ -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()
34 changes: 34 additions & 0 deletions python lessons/lerarned_pathlib.py
Original file line number Diff line number Diff line change
@@ -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)
63 changes: 39 additions & 24 deletions python lessons/loggings.py
Original file line number Diff line number Diff line change
@@ -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)
5 changes: 5 additions & 0 deletions python lessons/question.md
Original file line number Diff line number Diff line change
@@ -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
- []
27 changes: 27 additions & 0 deletions test.log
Original file line number Diff line number Diff line change
@@ -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: <class 'Exception'>: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: <class 'Exception'>: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 <function error_handling at 0x7baf6cb20c20>: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