python Log file - colorful, daily rotating

이미지
 You need to keep track of the events or activities that occur during the execution of the program you are developing now. You create a log file for this purpose. Log files are also necessary for debugging during development. Log files that serve this purpose must contain the following entry: Logging time : The time when the log is written. It can be expressed in mili second units. However, if the log frequency is low, the log in seconds may be OK. Log Level : It represents the importance of the log and is generally divided into debug, info, notice, .. error, and so on. Log contents : What you want to record. It is good to be compact and to express the contents clearly. The most used package for logging in Python is logging. I think even people who use the logging library a lot have not used many handlers other than StreamHandler and FileHandler. However, FileHandler is insufficient for managing log files by splitting them into time units or days. A module that can manage log files...

Python Websocket Programming

이미지
 There are many libraries for websocket programming in Python. Among them, the most used one is websockets. This library can be used for both server and client development, and is especially suitable for server use because it can be developed in an asynchronous manner. And for client programming, the wrbsocket-client library is often used along with websockets.  I will simply create an echo server using websockets and an echo client using sebsocket-client. Echo Server import asyncio from websockets.server import serve async def echo (websocket): async for message in websocket: print( "RCV ->echo:" , message) await websocket . send(message) async def main (): async with serve(echo, "" , 8765 ): await asyncio . Future() # run forever asyncio . run(main()) Echo Client The part that receives user input can run on an independent thread. import websocket import time import threading def...

Python - ttkbootstrap widgets layout #3 grid

이미지
 A grid is the easiest way to place complex widget layouts. Like the Excel we commonly use, widgets can be placed using row and column numbers. The following is a simple example of arranging a widget using two rows and two columns. import ttkbootstrap as tb app = tb . Window() app . style . theme_use( "superhero" ) app . geometry( "750x450" ) frame = tb . Frame(app, bootstyle = "primary" , width = 100 , height = 100 ) frame . grid(column = 0 , row = 0 ) frame2 = tb . Frame(app, bootstyle = "warning" , width = 100 , height = 100 ) frame2 . grid(column = 1 , row = 0 ) app . mainloop() <basic_grid.py> def grid ( cnf: Mapping[str, Any] | None = {}, * , column: int = ... , columnspan: int = ... , row: int = ... , rowspan: int = ... , ipadx: _ScreenUnits = ... , ipady: _ScreenUnits = ... , padx: _ScreenUnits | tuple[_ScreenUnits, _ScreenU...