Alekhya Nagulavancha

Alekhya Nagulavancha

11 Articles Published

Articles by Alekhya Nagulavancha

11 articles

How can I iterate over files in a given directory in Python?

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 27-May-2025 11K+ Views

Iterating over files in a given directory helps to perform tasks such as finding files that match certain criteria or, counting the number of files in a directory. Python provides the following five ways to walk through all the existing files in a directory - os.listdir() method os.walk() method os.scandir() method Using pathlib module glob.iglob() method In this article, we are going to see all the above methods that are used to iterate over files in a given ...

Read More

How to scan through a directory recursively in Python?

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 15-May-2025 15K+ Views

A directory is simply defined as a collection of subdirectories and single files or either one of them. A directory hierarchy is constructed by organizing all the files and subdirectories within a main directory and this is also known as root directory. These subdirectories are separated using a / operator in a directory hierarchy. In python, we have different methods to scan through a directory recursively. In this article we are going to see about each method. Using os.walk() method Using glob.glob() method Using os.listdir() method ...

Read More

How to calculate a directory size using Python?

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 29-Apr-2025 8K+ Views

A directory is simply defined as a collection of subdirectories and single files or either one of them. These subdirectories are separated using a "/" operator in a directory hierarchy. A directory hierarchy is constructed by organizing all the files and subdirectories within a main directory and also known as the "root" directory. Calculating the total size of a directory, i.e., all its files and subdirectories which is a common task in Python, especially when dealing with disk usage monitoring, backup management, or cleaning up storage. Python provides multiple ways to accomplish this efficiently using built-in modules such as os ...

Read More

Multi-Line Statements in Python

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 19-Apr-2023 7K+ Views

In Python, statements are nothing but instructions given to a Python interpreter to understand and carry out. These statements are usually written in a single line of code. But, that does not mean Python does not have a provision to write these statements in multiple lines. There are two types of statements in Python. They are assignment statements and expression statements. Both of them can be broken into multiple lines of statements and Python interpreter will have no problem understanding them. There are various ways to structure these multi-line statements in Python. Some of them include the following − ...

Read More

How to find if a directory exists in Python?

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 24-Feb-2023 8K+ 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 print full path of current file's directory in Python?

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 24-Feb-2023 19K+ Views

The path of a current file is defined with the help of directory hierarchy; and it contains the backtracked path from the current file to the root directory this file is present in. For instance, consider a file “my_file” belongs to a directory “my_directory”, the path for this file is defined as given below ./my_directory/my_file The directory, sub-directory and the file are all separated using the “/” separator in the path. Therefore, to get current file's full path, you can use the os.path.abspath() function. If you want only the directory path, you can call os.path.dirname() method. Using os.path.abspath() Method ...

Read More

Python Program to calculate the volume and area of Sphere

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 26-Oct-2022 7K+ Views

A sphere (solid) is usually considered a two-dimensional figure even though the figure is seen in three planes from its center. The main reason for this is that, a sphere is only measured using its radius. However, a hollow sphere is considered a three-dimensional figure since it contains space within its spherical walls and has two different radii to measure its dimensions. The spherical figure only has total surface area since there is only one dimension to measure the entire object. The formula to calculate the surface area of a sphere is − Area of solid sphere − $\mathrm{{4\pi ...

Read More

Python Program to calculate the area of the rhombus

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 26-Oct-2022 2K+ Views

A rhombus is a four-sided polygon that has all equal edges and perpendicular diagonals. It is also called as a special type of parallelogram, since a parallelogram has equal opposite sides and is shaped similar. The area of a rhombus is calculated with its diagonals, as they form four triangles within the figure. The combination of the area of all those triangles will give us the area of a rhombus. The mathematical formula is − Area − $\mathrm{{\frac{p\:\times\:q}{2}}}$ Where, p and q are the lengths of diagonals. Input Output Scenarios Let us look at some input output scenarios to ...

Read More

Python Program to calculate the volume and area of Cone

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 26-Oct-2022 5K+ Views

A cone is a three-dimensional figure that is formed by connecting infinite line segments from a common point to all the points in a circular base. This common point is also known as an apex. The cone is measured using three dimensions: radius of its circular base, height and lateral height. The difference between a cone’s height and lateral height is such that− height is measured from the apex to the center of the circular base, while lateral height is a length of line segments connecting apex and any point on the circular base. The lateral surface area, also ...

Read More

Python Program to calculate the volume and area of the Cylinder

Alekhya Nagulavancha
Alekhya Nagulavancha
Updated on 14-Oct-2022 3K+ Views

In this article, we will look into a python program to calculate the volume and area of a cylinder. A cylinder is defined as a 3D object that has two circles connected with a rectangular surface. The special thing about a cylinder is that even though it is measured using just two dimensions, i.e. the height and radius, the cylinder is considered a three-dimensional figure as it is measured in xyz coordinate axes. The area of the cylinder is calculated is two ways− area of the lateral surface and area of the total surface. Lateral surface area is only the ...

Read More
Showing 1–10 of 11 articles
« Prev 1 2 Next »
Advertisements