Found 27104 Articles for Server Side Programming

How to scan through a directory recursively in Python?

Alekhya Nagulavancha
Updated on 24-Feb-2023 12:08:19

10K+ 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, also known as “root” directory. These subdirectories are separated using a “/” operator in a directory hierarchy. Since the directory is organized in the form of a hierarchy/tree, scanning it can be likened to traversing a tree. And to do that, there are various ways. Using os.walk() method Using glob.glob() method Using os.listdir() method The directories are handled by the operating system; therefore, whenever ... Read More

How to get the home directory in Python?

Rajendra Dharmkar
Updated on 11-Sep-2023 17:00:43

3K+ Views

As a Python coder, you may often come across scenarios where you need to access the user's home directory to perform specific operations like reading or writing user−specific files, configuration files, or data. However, the location of the home directory can change across different operating systems, making it a challenge to access it in a platform−independent manner. In this extensive article, we will explore various methods to obtain the home directory in Python effectively and efficiently. We will proceed to provide step−by−step explanations and code examples to understand the process. Whether you're developing a cross−platform application or simply need to ... Read More

How to find if a directory exists in Python?

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

6K+ 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?

Rajendra Dharmkar
Updated on 03-Aug-2023 13:21:27

1K+ Views

In the domain of Python programming, organization and modularity are pivotal in crafting efficient and maintainable code. As your Python projects grow in complexity, the necessity to disseminate common data across multiple files becomes paramount. Gratefully, Python furnishes several techniques to accomplish this seamlessly. Within this article, we shall embark on a journey of a few distinct methods to share common data among multiple Python files. Each approach boasts its unique strengths and adaptability, endowing you with the ability to construct scalable and robust Python projects. You will be guided through each method with comprehensive explanations in a human-friendly style. ... Read More

How to find difference between 2 files in Python?

Rajendra Dharmkar
Updated on 03-Aug-2023 11:42:42

8K+ Views

When you venture into the realm of file processing, the need to discern disparities and differences between two files arises frequently. Python equips us with an array of potent tools to accomplish this task with ease and precision. In this article, we shall navigate a few distinct methodologies to reveal the differences between two files in Python. Each approach is equipped with unique functionalities and adaptability, granting you the ability to seamlessly compare files of varying sizes and formats. As a Python coding enthusiast, you are walked through each method, providing stepwise explanations in a style that is human-friendly. By ... Read More

How to execute a Python file in Python shell?

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

6K+ 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

How can we read inputs as integers in Python?

Alekhya Nagulavancha
Updated on 24-Feb-2023 12:25:34

20K+ Views

In Python, there are two ways to provide input information to a program. One in which we directly assign input objects to object references/variables; and the other in which the program takes user input dynamically (during runtime). Python 2.x versions use raw_input() function to take user input dynamically; whereas, Python 3.x versions use input() function. The input() function only takes input values in the form of strings, by default. In this article, we will learn how to read the input as “Numbers” in Python 3.x using input() function. Reading Inputs as Numbers Python, like any other programming languages, accepts two ... Read More

How do we use Python in script mode?

Alekhya Nagulavancha
Updated on 19-Apr-2023 14:54:50

2K+ Views

Python is a high level programming language that helps a user to run a program and integrate systems more efficiently; as it executes a program in comparatively fewer lines of code. In this programming language, a code can be run in two ways− Interactive mode, and Script mode In this article, we will learn how to execute a python code in a script mode. Python in Script Mode A script mode in Programming languages is nothing but putting all the lines of code in a python program into a file, also known as a script, and ... Read More

How do we use Python in interactive mode?

Alekhya Nagulavancha
Updated on 19-Apr-2023 14:53:51

1K+ Views

Python is a high level programming language that helps a user to run a program and integrate systems more efficiently; as it executes a program in comparatively fewer lines of code. In this programming language, a code can be run in two ways − Interactive mode, and Script mode Note − To run a python code interactively, we use the command prompt in Windows, terminal in Linux and macOS, etc. In this article, we will learn how to execute a python code in interactive mode in Windows. However, the commands are almost same in other operating ... Read More

How do we access command line arguments in Python?

Alekhya Nagulavancha
Updated on 21-Apr-2023 11:54:57

342 Views

Command line is the place where executable commands are given to operating system. A Python script can be executed by writing its name in front of python executable in the command line. C:\users\acer>python test.py If you want some data elements to be passed to Python script for its processing, these elements are written as space delimited values in continuation to name of script. This list of space delimited values is called command line arguments. For example, C:\users\acer>python test.py Hello TutorialsPoint When there exists a way to pass arguments through the command line, there must also exist a way ... Read More

Advertisements