Sunday, October 9, 2022

Websockets and asyncio with web server and client

 server side=>

import asyncio
import websockets
async def response(websocket, path):
message = await websocket.recv()
print(f"We got the message from the client: {message}")
await websocket.send("I can confirm I got your message!")
start_server = websockets.serve(response, 'localhost', 1234)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()

client side=>

import asyncio
import websockets
async def message():
async with websockets.connect("ws://localhost:1234") as socket:
msg = input("What do you want to send: ")
await socket.send(msg)
print(await socket.recv())
asyncio.get_event_loop().run_until_complete(message())

Friday, October 7, 2022

Type checking with mypy and Type hints

 Hi,

Today I'm gonna show you type hints in python. 

Firstly you should install mypy

pip install mypy


Here is the example:


Basically we are defining to data types.

 For more information link is below:

http://mypy-lang.org/

Writing a PEP8 Standart of Python Code


Hi, 


I use flake8 in my code you should install :

pip install flake8


After that you can use like:

 flake8 example.py



In the Visual Studio Code you can use cornflakes-linter
















If you want to ignore some error create a 

.flake8

file and write:

[flake8]

ignore=E501 


Example ss for flake8 and cornflakes-linter in VS Code





This is the website of flake8 you can check for more details.

https://flake8.pycqa.org/en/latest/


This is the website of pep8 you can check for more details.
 https://pep8.org/

file tree for nodejs project

 find . \( -path "*/node_modules" -o -path "*/.git" \) -prune -o -print | tree -a -I 'node_modules|.git'