Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
-
Economics & Finance
Articles on Trending Technologies
Technical articles with clear explanations and examples
Synchronization and Pooling of processes in Python
Python's multiprocessing module provides tools for synchronization and process pooling to handle concurrent execution. Synchronization ensures processes don't interfere with each other, while pooling manages multiple worker processes efficiently. Synchronization Between Processes The multiprocessing package supports spawning processes using an API similar to the threading module. It works on both Windows and UNIX operating systems and provides synchronization primitives to coordinate between processes. Example Here's how to use a Lock to synchronize output from multiple processes ? from multiprocessing import Process, Lock def my_function(lock, num): lock.acquire() ...
Read MorePlotting solar image in Python
Python provides the SunPy package for working with solar physics data and creating solar images. This package includes various solar datasets from observatories and labs, containing proton/electron flux data and imaging data. You can install SunPy using the following command ? pip install sunpy What is AIA? The Atmospheric Imaging Assembly (AIA) is an instrument aboard the Solar Dynamics Observatory (SDO) that captures high-resolution images of the Sun's atmosphere in multiple wavelengths. The AIA provides crucial data for understanding solar activity and space weather. Creating a Solar Map SunPy uses the Map ...
Read MoreScraping and Finding Ordered Word in a Dictionary in Python
Scraping web content and finding words with alphabetically ordered characters is a common text processing task in Python. This article shows how to fetch text data from a URL and identify words where characters are arranged in alphabetical order. Installing Required Module First, install the requests module for web scraping ? pip install requests Web Scraping Process The scraping involves these key steps ? Import the requests module Fetch data from a URL Decode the response using UTF-8 Convert the text into a list of words Finding Ordered Words ...
Read MoreUnderscore(_) in Python
In Python, the underscore (_) character has several special uses and naming conventions. Understanding these patterns helps you write more Pythonic code and follow established conventions. Single Underscore in Interpreter The Python interpreter automatically stores the result of the last expression in the special variable _ ? # In interactive Python interpreter print(10 + 5) print(_) # Access last result print(_ * 2) # Use it in calculations 15 15 30 Ignoring Values in Unpacking Use _ as a throwaway variable when you don't need certain values during ...
Read MoreMerge two sorted arrays in Python using heapq?
The heapq module in Python provides an efficient way to merge multiple sorted iterables into a single sorted sequence. The heapq.merge() function is specifically designed for merging sorted arrays while maintaining the sorted order. The heapq.merge() Function The heapq.merge() function accepts multiple sorted iterables and returns an iterator that produces elements in sorted order. It uses a min-heap internally to efficiently merge the arrays without loading everything into memory at once. Syntax heapq.merge(*iterables, key=None, reverse=False) Basic Example Here's how to merge two sorted arrays using heapq.merge() ? import heapq ...
Read MoreCreating child process using fork() in Python
The fork() function in Python allows you to create child processes by duplicating the current process. This is a fundamental concept in Unix-like systems for process management and multithreading environments. When fork() is called, it creates an exact copy of the calling process. The return value helps distinguish between parent and child processes: 0 indicates the child process, a positive value indicates the parent process (containing the child's PID), and a negative value indicates an error occurred. Understanding fork() Return Values The fork() function returns different values depending on which process you're in ? Child ...
Read MorePlay a video in reverse mode using Python OpenCv
OpenCV (Open Source Computer Vision) is a powerful library for image and video processing in Python. One interesting application is playing videos in reverse mode by manipulating the frame order. Application Areas of OpenCV Facial recognition system Motion tracking Artificial neural network Deep neural network Video streaming Installation For Windows ? pip install opencv-python For Linux ? sudo apt-get install python-opencv Steps to Play Video in Reverse Import OpenCV library (cv2) Load the video file as input Extract all frames from the video and ...
Read MoreRead and Write to an excel file using Python openpyxl module
Python provides the openpyxl module for reading and writing Excel files. This powerful library allows you to create, modify, and extract data from Excel workbooks programmatically. Installation Install openpyxl using pip ? pip install openpyxl Getting Sheet Title When you create a new workbook, it comes with a default sheet ? import openpyxl my_wb = openpyxl.Workbook() my_sheet = my_wb.active my_sheet_title = my_sheet.title print("My sheet title: " + my_sheet_title) My sheet title: Sheet Changing Sheet Title You can customize the sheet name by modifying the ...
Read MoreDecimal Functions in Python
The Decimal module in Python provides precise decimal floating-point arithmetic, avoiding the common rounding errors that occur with standard floating-point numbers. This module is particularly useful for financial calculations where precision is critical. To use the Decimal module, you need to import it first ? import decimal Square Root and Exponential Functions The sqrt() method calculates the square root of a decimal number, while exp() returns ex for a given decimal value ? import decimal my_dec = decimal.Decimal(25.36) print(my_dec) print('Square Root is:', my_dec.sqrt()) print('e^x is:', my_dec.exp()) 25.3599999999999994315658113919198513031005859375 Square ...
Read MoreCreate a Website Alarm Using Python
In this section we will see how to create a website alarm system using Python. This tool automatically opens a specified website URL in your browser at a predetermined time. Problem Statement Create a program that opens a website URL on the browser by taking a website URL and time as input. When the system time reaches the specified time, the webpage will be opened automatically. We can store different web pages in our bookmark sections. Sometimes we need to open some web pages every day at a specific time to do some work. For that purpose, ...
Read More