simple way to merge list data2.category >>> 437624 [16] 437625 [23] 437627 [23] 437628 [9, 0, 23, 10] 437629 [19, 20, 23] ... tolist = data2.category.tolist() tolist = sum(tolist, []) >>> [16, 23, 23, 0, 9, ...] Basic Python/Workbook 2022.11.22
vars vars Return thd dictionary attribute. class Person: name = "John" age = 36 country = "norway" x = vars(Person) print(x) >>> {'__module__': '__main__', 'name': 'John', 'age': 36, 'country': 'norway', '__dict__': , '__weakref__': , '__doc__': None} Basic Python 2022.08.25
FastAPI-GET and POST How HTTP works 1. Request('what', 'how') : Client(Browser) → Server ↑Through HTTP Request Message 2. Response : Server → Client(Browser) ↑Contains request information Message has Method(which means 'how') HEADER BODY GET VS POST GET POST Whether data is exposed on URL Yes No URL Example http://localhost:8080/items/?item_id=123&q=100 http://localhost:8080/items Data Location Header Body Caching A.. Basic Python/FastAPI 2022.07.21
FastAPI-Request Body - Request Body(Not Necessarily) : send data from a Client(a browser) → API - Response Body(Necessarily) : data from API → a Client(a browser) Step 1. Declare a request body using Pydantic. from pydantic import BaseModel 2. Declare the data model as a class that inherits from BaseModel. class Item(BaseModel): name: str description: Union[str, None] = None price: float tax: Union[float, None] = No.. Basic Python/FastAPI 2022.07.20
FastAPI Step 1. Import FastAPI. 2. Create an app instance. 3. Write a path operation decorator (like @app.get("/")). 4. Write a path operation function. 5. Run the development server. #bash % uvicorn main:app --reload 6. Open the browser. Ex 1. #main.py from fastapi import FastAPI app=FastAPI() @app.get('/') async def read_bot(): return {'hello':'world'} FastAPI() : an object app : variable containing i.. Basic Python/FastAPI 2022.07.14