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
Programming Articles
Page 70 of 2547
How to check if an object is iterable in Python?
An iterable object is any object that can be iterated through all its elements using a loop or iterable function. Lists, strings, dictionaries, tuples, and sets are all iterable objects in Python. There are several reliable methods to check if an object is iterable. Let's explore the most effective approaches. Using try-except with iter() The most Pythonic way is to use iter() function inside a try-except block. This approach follows the "easier to ask for forgiveness than permission" (EAFP) principle ? # Check if a list is iterable data = ["apple", 22, "orange", 34, "abc", ...
Read MoreHow to check if an application is open in Python?
A process is a program under execution. When an application runs on your operating system, it creates one or more processes. Python provides several methods to check if a specific application is currently running on your system. We'll explore three different approaches to check if an application is open: using the psutil module, the subprocess module, and the wmi module for Windows systems. Using psutil.process_iter() Function The psutil module provides a cross-platform interface for retrieving information about running processes and system utilization. It works on Linux, Windows, macOS, Solaris, and AIX. First, install psutil using ? ...
Read MoreHow to check the file size?
Files are used to store certain data based on user requirement. A file can contain any type of information such as audio, text, images, video or program. Depending on the data present in a file, the size of a file varies. The size of a file is measured in bits or bytes. A bit is the smallest unit of information which is typically represented by a single value: either 0 or 1. Bytes are used to measure the amount of data in a file and the bytes are denoted by 8 bits. There are several ways to check the ...
Read MoreHow to check Django version?
Django is a free, open source web framework written in Python that follows the Model-View-Controller (MVC) architectural pattern. It's designed to help developers build web applications quickly and efficiently with minimal complexity. The key features of the Django framework include: Object-Relational Mapper (ORM) for database management URL routing and HTTP request/response handling Template engines for generating HTML pages Built-in user authentication and administration Support for third-party modules and packages Community support and comprehensive documentation Django is widely used by organizations like Google, Pinterest, Mozilla, and Instagram for building scalable and robust web applications. Installing ...
Read MoreHow to check any script is running in linux using Python?
The psutil module in Python helps us retrieve information about processes currently running on our Linux system. This is essential for monitoring and managing scripts programmatically. What is a Script? A script is a set of instructions written in a programming language and executed by the computer. Scripts help us perform repetitive tasks efficiently, from simple file operations to complex system administration. In Linux, scripts are typically executed through command line using shell interpreters like Bash or Python interpreters. These scripts can be scheduled using cron or systemd timers. Method 1: Using psutil Module The psutil ...
Read MoreHow to change ticks label sizes using Python’s Bokeh
Bokeh is a powerful Python data visualization library that creates interactive plots and dashboards for web browsers. When working with Bokeh plots, you may need to customize the tick label sizes to improve readability and visual appeal. This article demonstrates how to change tick label sizes using various Bokeh formatting options. Understanding Tick Labels in Bokeh Tick labels are the text labels that appear along the axes of a plot, indicating the values at specific tick marks. In Bokeh, you can customize these labels using the axis properties and formatting options. Installing Bokeh First, install the ...
Read MoreWays to Convert Boolean Values to Integer in Python
Python is a widely used programming language for web development, data science, machine learning, and automation. Boolean values in Python are represented as True and False. When converting to integers, True becomes 1 and False becomes 0. This article explores different methods to convert Boolean values to integers. Using the int() Function The simplest way to convert Boolean values to integers is using Python's built-in int() function ? # Converting True to integer boolean_value = True integer_result = int(boolean_value) print(f"True converted to integer: {integer_result}") # Converting False to integer boolean_value = False integer_result = int(boolean_value) ...
Read MoreHow to change the PyGame icon?
While building video games, we often want to set a custom image or logo for the developed game. Python's Pygame library provides the set_icon() function to set a custom window icon. Pygame is a set of modules that allows us to develop games and multimedia applications. This is built on top of the SDL (Simple Direct Media Layer) library which provides low-level access to audio, keyboard, mouse, joystick, and graphics hardware through OpenGL and Direct3D. Syntax Following is the syntax for setting the icon for the game ? pygame_icon = pygame.image.load("image_name") pygame.display.set_icon(pygame_icon) Where, ...
Read MoreHow to change the position of legend in Pygal?
Pygal is a Python data visualization library designed to create interactive charts and graphs. Built with advanced SVG (Scalable Vector Graphics) features, it produces high-quality graphics that can be easily embedded into web pages and applications. Installing Pygal You can install Pygal using pip ? pip install pygal Understanding Legends in Pygal The legend adds context and clarity to charts by displaying the names of each data series and their corresponding colors. By default, legends appear at the top of Pygal charts. Changing Legend Position Syntax To change the legend ...
Read MoreWays to Concatenate Boolean to String in Python
Converting Boolean values to strings is a common task in Python programming. Python provides several methods to concatenate Boolean values with strings, each with its own advantages and use cases. Using str() Function The most straightforward approach is using the str() function to convert Boolean values to strings ? # Converting True to string is_active = True message = "User status: " + str(is_active) print(message) # Converting False to string is_logged_in = False status = "Login status: " + str(is_logged_in) print(status) User status: True Login status: False Using f-strings (Formatted ...
Read More