How to Show Progress Bar in Python

How to Show Progress Bar In Python? Let’s have a look at tqdm Python package which helps in showing progress bar in Python and CLI. Show Progress Bar I’m having Python 2.7.18 installed in my system. You can install the tqdm package using pip. pip install tqdm Once it’s installed let’s create a file called app.py and import the tqdm package. from tqdm import tqdm To show some time delay, let’s import the sleep package from time module. [Read More]

Python Try Except Else Finally

Try Except Else Finally in Python. Let’s have a look at the below code: try: k = m['name'] except: print('error occured') else: print('all good') finally: print('Done') If an exception occurs in the code running between the try and except block, except block statements are executed. If nothing breaks in the try and except block, else block is executed. And at the end the finally block code gets executed. The above code outputs: [Read More]

Center Div Inside Div

How to Center Div Inside Div? Let’s say this is your HTML where you have two div inside a container div. <html> <head> <style> .container{ border: 1px solid red; height: 200px; } .div1, .div2{ border: 1px solid green; height: 50px; } </style> </head> <body> <div class="container"> <div class="div1"> Div 1 </div> <div class="div2"> Div 2 </div> </div> </body> </html> Here is how it looks: To center align contents inside a div you can use use CSS Flexbox layout. [Read More]

Conditional Class in Angular

How to set conditional classes in Angular?

You can set the class of an element dynamically using ngClass directive.

[ngClass]="{'red': a < 5 , 'blue' : a > 10}"

From the above code, class red or blue will be set if the conditions are satisfied. If both the conditions are satisfied, then the element is assigned both the classes.

Connect Node.js Express to MySQL

How to connect Node.js Express App To MySQL? You’ll be requiring a connector to connect Node Express app to MySQL database. Start by installing the mysql connector module in your node project. npm install mysql --save Once you have the connector installed, rquire the module in your node app. const mysql_connector = require('mysql'); Now create a connection using the createConnection method of the connector instance. const connection = mysql_connector.createConnection({ host : 'localhost', user : 'root', password :'root', database : 'expense_manager' }); Once you have the connection object you need to make the connection using the connect method. [Read More]

Creating Your First Web Page | HTML | CSS

Creating your first webpage using HTML, CSS, JavaScript. Start by creating a file called index.html. Every html page has a .html extension. Inside the html file you have three main tags, html, head and body tag. All your HTML content comes inside the html tag. Inside the html tag you define your head and body tag. <html> <head> </head> <body> </body> </html> For styling up your HTML page you can make use of stylesheets which you can define inside the head tag. [Read More]

No matching distribution found for fastapi

Could not find a version that satisfies the requirement fastapi (from versions: ) No matching distribution found for fastapi I was getting the following while trying to install FastAPI. The issue was I had two Python versions installed in my system and I was trying to install it using pip from Python2.7. Once I tried to install using Python3.9 it worked fine. C:\Users\Jay>C:\Users\Jay\AppData\Local\Programs\Python\Python39\Scripts\pip.exe install fastapi Collecting fastapi Downloading fastapi-0.68.0-py3-none-any.whl (52 kB) |████████████████████████████████| 52 kB 235 kB/s Collecting pydantic! [Read More]

Passing Query Parameters in FastAPI

How to pass query parameters in Python FastAPI ? Once you have installed FastAPI, let’s see how to pass query parameters in FastAPI. Here I have defined an endpoint in my FastAPI app. from fastapi import FastAPI my_app = FastAPI() @my_app.get("/getUserInfo") def getUserInfo(): return [{ "id" : 100, "firstName" : "roy" }] You can run the app using uvicorn app:my_app. It will run an app on http://localhost:8000. You will be able to access the endpoint at http://localhost:8000/getUserInfo. [Read More]

Post JSON to FastAPI

How to pass JSON to POST request in FastAPI ? You can pass paramters to the FastAPI POST endpoint using pydantic. But to use pydantic you need to pre define the JSON structure. What if you don’t know the structure? You can access the passed request body using request. Start by importing request from FastAPI. from fastapi import Request Declare the type of the parameter as Request. When passing pre defined JSON structure or model to POST request we had set the parameter type as the pre defined model. [Read More]

Python API Using FastAPI

Creating Python API Using FastAPI Framework. First you need to install FastAPI using pip. pip install fastapi If you are getting any error like No matching distribution found for fastapi you are probably using pip from Python2. Check this post on how to resolve the issue. Now once you have installed fastapi, you need to install uvicorn. pip install uvicorn Create a file called app.py. Import the FastAPI. from fastapi import FastAPI Create an app using fastapi. [Read More]