Category: Python

  • How to use try except in python

    Python’s exception handling system lets you write code that can deal with unexpected errors The structure Explanation of the structure: The try…except structure in Python aims to prevent programs from crashing by providing a way to handle exceptions. This allows you to continue execution or provide meaningful error messages instead of the program terminating unexpectedly.…

  • Python for Beginners: Turning Numbers into Text (String Conversion)

    Converting to Text with python built in str() Function Its simple and easy We can convert number to string like this . here x=10 , where the value of x is a number when we write x=str(x) it becomes a string. Thats all! x=10 x=str(x) So we can convert number to string with str() number…

  • Building a Simple and Secure API with Python Flask

    Server-Side: Flask API Development We will build a simple API that will tell the current time. And then add more feature. The explanation and the code The code from flask import Flask, request, jsonify from datetime import datetime app = Flask(__name__) # Define a route to get the current time @app.route(‘/get-current-time’, methods=[‘POST’]) def get_current_time(): #…

  • Using Environment Variables in Python: Easy Quick Guide

    What are environment variables? Think of them like secret notes your programs can read. These notes hold important information like: Why are environment variables important? Why Use Environment Variables for Application Security and Flexibility? Sensitive information like API keys and encryption keys are the essential for modern applications. Adding them directly within your code introduces…

  • Flask File Handling Made Easy: Upload and Download Files

    Very basic example code_features This is our first example… Run this code first. Then read the step by step explanation. That will be more effective. Because this tutorial is all about practice. In this article covers simple upload, upload to database, securing the upload by adding limiting file extension and adding download link… Run the…

  • How to use python enumerate

    Enumerate helps to track the index and element. Though we can gain the same feature using for loop but enumerate makes the code more readable Imagine we have a list of colors color_names = [‘Red’, ‘Orange’, ‘Yellow’, ‘Green’, ‘Blue’, ‘Purple’, ‘Pink’, ‘Brown’,’Cyan’] For tracking both the index and corresponding element we can write this simple…

  • How To Generate URL And Route Dynamically In Flask

    We can set route dynamically instead of fixed route. For example In the pre-determined route links generate like this example.com/users/profile In the dynamically gendered route will be like this example.com/users/custom_profile_name We will use @app.route(‘/<username>’) The code will be like this We can use anything in the <username> here So if we load page like example.com/anything_here…

  • Python Flask : Starter Automated Template

    When starting new project again, Some common structure needed to be written again and again. So I wrote a program nearly three years (2021) ago to Get Everything ready on one script. Here is the python script that makes everything ready Here is is the revised version of the code The Program Automatically generates basic…