Found 34472 Articles for Programming

How are entire non-empty directory trees removed using Python?

Rajendra Dharmkar
Updated on 22-Aug-2023 11:21:06

123 Views

It is very well known in the vast domain of computer programming that the efficient handling of file and directory operations is paramount to effective data management. There will be instances in our routine work, where we encounter the need to remove entire directory trees, along with all their subdirectories and files. Python, a multipurpose and powerful programming language, equips developers with a robust module called ‘shutil’ module to handle such directory tasks effectively. In this extensive tutorial, we will explore the intricate process of removing entire non-empty directory trees using Python's 'shutil' module. Throughout this article, we will present ... Read More

How is a file read using a limited buffer size using Python?

Rajendra Dharmkar
Updated on 11-Sep-2023 16:29:36

784 Views

In the world of computer programming, file handling is a very essential aspect of managing data efficiently. At times, when we are required to deal with large files, it may be that reading the entire file into memory may not be practical or efficient. In such situations, reading a file using a limited buffer size can be a more practical approach and solution. Python, a versatile and robust language, provides developers with powerful tools to perform file operations effectively. In this comprehensive article, we will explore different ways of carrying out the process of reading a file using a limited ... Read More

What is an array data structure in Java?

Sai Subramanyam
Updated on 30-Jul-2019 22:30:20

161 Views

Array is a container which can hold a fix number of items and these items should be of the same type. Most of the data structures make use of arrays to implement their algorithms. Following are the important terms to understand the concept of Array. Element − Each item stored in an array is called an element. Index − Each location of an element in an array has a numerical index, which is used to identify the element. Example Live Demo public class ArrayExample { public static void main(String args[]){ int myArray[] = {44, 69, 89, 635}; for (int i = 0; i

How an entire file is read into buffer and returned as a string in Python?

Rajendra Dharmkar
Updated on 22-Aug-2023 11:18:52

6K+ Views

In the dynamic world of computer programming, file handling, and data manipulation form the backbone of numerous tasks. Python, a powerful and versatile language, offers developers a plethora of methods to achieve efficient file operations. In this comprehensive guide, we delve into the art of reading entire files into buffers and returning them as strings in Python. With step-by-step explanations and practical code examples, we equip you with the skills to navigate the realm of file handling with finesse. Understanding File Reading and Buffering Before embarking on our code journey, it's crucial to grasp the fundamentals of file reading and ... Read More

What are the types of arrays in Java?

Lakshmi Srinivas
Updated on 30-Jul-2019 22:30:20

15K+ Views

There are two types of arrays in Java they are − Single dimensional array − A single dimensional array of Java is a normal array where, the array contains sequential elements (of same type) − int[] myArray = {10, 20, 30, 40} Example Live Demo public class TestArray { public static void main(String[] args) { double[] myList = {1.9, 2.9, 3.4, 3.5}; // Print all the array elements ... Read More

How to print characters from a string starting from 3rd to 5th in Python?

Sarika Singh
Updated on 18-Aug-2022 11:50:52

8K+ Views

Python uses arrays of bytes called strings to represent unicode characters. In Python, string indexing ranges from 0 to n-1, where n is the length of the string. In a string of size n, characters can therefore be retrieved from 0 to n-1. For instance, the index of the text “Coding” is 0, 1, 2, 3, 4, 5. The first character in the string “Coding” is represented by the number 0, and the characters o, d, i, n, and g are represented by the numbers 1, 2, 3, and 5, respectively. Printing characters of a string Characters can be put ... Read More

What is the maximum size of list in Python?

Pythonic
Updated on 30-Jul-2019 22:30:20

4K+ Views

Maximum length of a list is platform dependent and depends upon address space and/or RAM. The maxsize constant defined in sys module returns 263-1 on 64 bit system. >>> import sys >>> sys.maxsize 9223372036854775807 The largest positive integer supported by the platform's Py_ssize_t type, is the maximum size lists, strings, dicts, and many other containers can have.

What is the maximum length of string in Python?

Pythonic
Updated on 30-Jul-2019 22:30:20

5K+ Views

Maximum length of a string is platform dependent and depends upon address space and/or RAM. The maxsize constant defined in sys module returns 263-1 on 64 bit system. >>> import sys >>> sys.maxsize 9223372036854775807 The largest positive integer supported by the platform's Py_ssize_t type, is the maximum size lists, strings, dicts, and many other containers can have.

What is the maximum value of float in Python?

Pythonic
Updated on 30-Jul-2019 22:30:20

656 Views

In sys module, a struct sequence (tuple of named elements) called float_info has been defined. In this structure, an element max returns maximum representable finite float number. >>> import sys >>> sys.float_info.max 1.7976931348623157e+308

How to sort a dictionary in Python by keys?

Pythonic
Updated on 30-Jul-2019 22:30:20

504 Views

Standard distribution of Python contains collections module. It has definitions of high performance container data types. OrderedDict is a sub class of dictionary which remembers the order of entries added in dictionary object. When iterating over an ordered dictionary, the items are returned in the order their keys were first added. >>> from collections import OrderedDict >>> D = {5:'fff', 3:'ttt', 1:'ooo', 4:'bbb', 2:'ddd'} >>> OrderedDict(D.items())  OrderedDict([(5, 'fff'), (3, 'ttt'), (1, 'ooo'), (4, 'bbb'), (2, 'ddd')]) We also need to use sorted() function that sorts elements in an iterable in a specified order. The function takes a function ... Read More

Advertisements