Found 33676 Articles for Programming

How to get the home directory in Python?

Niharikaa Aitam
Updated on 15-May-2025 15:45:11

8K+ Views

When we are building Python applications that store or retrieve user-specific files and settings, then we will often need to access the home directory. The home directory is the default location on a computer where user-related data is stored, such as documents, configuration files, and application data. Python provides simple and cross-platform ways of finding the home directory programmatically by making it easy to write code that works on Windows, macOS, and Linux without modifications. In this article, we'll explore the different methods to get the home directory in Python. Using os.path.expanduser("~") The os.path.expanduser() is a function in Python's built-in ... Read More

How to find if a directory exists in Python?

Alekhya Nagulavancha
Updated on 24-Feb-2023 12:13:45

7K+ Views

Directory creation is a common task for computer users. You might need to create a directory to store some files, or to place some new files inside an existing directory. In this article, you will learn how to find if a directory already exists in Python or not. A directory is a file system structure used by operating systems and software applications to organize files. It can also refer to a list of files and folders, like the current folder in Windows Explorer. Sometimes there arises a need to check whether a certain directory exists in a system or not; ... Read More

How to share common data among multiple Python files?

Niharikaa Aitam
Updated on 15-May-2025 18:28:13

2K+ Views

In Python, sharing common data such as constants, configuration settings or shared resources among multiple files is a routine task in modular application development. The data will be centralized in a dedicated module which allows it to be maintained in one place and imported wherever needed. Before proceeding with various approaches to share data among multiple Python files, first we need to understand what is a module and what is shared data. What is a Module? A Module is a Python file (.py) that contains definitions such as variables, functions, classes or runnable code. By placing shared data in its ... Read More

How to find difference between 2 files in Python?

Niharikaa Aitam
Updated on 15-May-2025 18:32:09

11K+ Views

In most of the applications, especially in data processing, software development or testing, it is required to compare two files to detect changes, validate outputs or find discrepancies. Python offers several ways to compare files which ranges from basic line-by-line comparisons to more advanced diff utilities. Following are the key methods which are used to compare two files in python - Line-by-line comparison: This is a straightforward approach to textual differences. difflib module: This module is used to produce human-readable diffs similar to Unix’s diff command. filecmp module: This module is used for quick binary or shallow comparisons. ... Read More

How (where) are the elements of an array stored in memory?

Priya Pallavi
Updated on 30-Jul-2019 22:30:20

2K+ Views

In Java, arrays are objects, therefore just like other objects arrays are stored in heap area. An array store primitive data types or reference (to derived data) types Just like objects the variable of the array holds the reference to the array.

Can i refer an element of one array from another array in java?

Nikitha N
Updated on 16-Jun-2020 10:04:41

530 Views

Yes, you can −int [] myArray1 = {23, 45, 78, 90, 10}; int [] myArray2 = {23, 45, myArray1[2], 90, 10};But, once you do so the second array stores the reference of the value, not the reference of the whole array. For this reason, any updating in the array will not affect the referred value −ExampleLive Demoimport java.util.Arrays; public class RefferencingAnotherArray {    public static void main(String args[]) {       int [] myArray1 = {23, 45, 78, 90, 10};       int [] myArray2 = {23, 45, myArray1[2], 90, 10};       System.out.println("Contents of the ... Read More

How to execute a Python file in Python shell?

Rajendra Dharmkar
Updated on 03-Aug-2023 11:21:15

8K+ Views

Venturing further into the realm of Python programming, you'll undoubtedly encounter scenarios where executing a Python file from within the Python shell becomes essential. This capability endows you with the power to test, run, and interact with your Python scripts seamlessly without exiting the Python environment. Within this article, we shall discuss some distinct methods to execute Python files within the Python shell, each offering its unique functionalities and adaptability, facilitating seamless interaction with your Python scripts. As a Python coding expert, I would walk you through each method with step-by-step explanations and examples in a lucid style that is ... Read More

What are variable length (Dynamic) Arrays in Java?

Srinivas Gorla
Updated on 19-Feb-2020 12:12:03

5K+ Views

In Java, Arrays are of fixed size. The size of the array will be decided at the time of creation. But if you still want to create Arrays of variable length you can do that using collections like array list.Exampleimport java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class AddingItemsDynamically {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter the size of the array :: ");       int size = sc.nextInt();       String myArray[] = new String[size];       System.out.println("Enter elements of the array (Strings) :: ");       for(int i=0; i

How to create a generic array in java?

Abhinanda Shri
Updated on 30-Jul-2019 22:30:20

258 Views

No, we can’t create generic arrays in java.

How to add items to an array in java dynamically?

Ankitha Reddy
Updated on 30-Jul-2019 22:30:20

11K+ Views

Since the size of an array is fixed you cannot add elements to it dynamically. But, if you still want to do it then, Convert the array to ArrayList object.Add the required element to the array list.Convert the Array list to array.Exampleimport java.util.ArrayList; import java.util.Arrays; import java.util.Scanner; public class AddingItemsDynamically {    public static void main(String args[]) {       Scanner sc = new Scanner(System.in);       System.out.println("Enter the size of the array :: ");       int size = sc.nextInt();       String myArray[] = new String[size];       System.out.println("Enter elements of the array ... Read More

Advertisements