Rajendra Dharmkar has Published 452 Articles

How to check if a file is a directory or a regular file in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 11-Sep-2023 16:35:54

418 Views

When working with files and directories in Python, it's a crucial point to distinguish between regular files and directories. Knowing the type of each file is most essential for implementing different file handling operations, such as reading, writing, or navigating through directory structures. Python makes available several methods and techniques ... Read More

How to change file extension in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 11-Sep-2023 16:32:46

13K+ Views

File extensions play a crucial role by helping in identifying the type of content a file holds. The task of changing the file extension is a common in various use cases, such as converting file formats, renaming files for compatibility, or ensuring files are correctly interpreted by specific applications. Python, ... Read More

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

Rajendra Dharmkar

Rajendra Dharmkar

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

756 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 ... Read More

How do you get a directory listing sorted by their name in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 11-Sep-2023 16:26:27

9K+ Views

When working with directories in Python, it's often necessary to obtain a list of files and subdirectories within a given directory. Moreover, sorting this directory listing by their names can be beneficial for better organization and readability. Python provides several methods and techniques to achieve this goal efficiently. Sorting the ... Read More

How do you get a directory listing sorted by creation date in Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 11-Sep-2023 16:23:26

6K+ Views

In the process of managing files and directories in Python, there are often situations where you need to obtain a directory listing sorted by creation date. The task of sorting files and directories by their creation timestamps can be beneficial for various purposes, such as analyzing the most recently added ... Read More

How are files extracted from a tar file using Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 11-Sep-2023 16:20:27

16K+ Views

You know, it's common knowledge that dealing with files and archives is like a daily routine in the computer programming domain. So, there's this popular archive type called a TAR file that makes it easy for combining and storing files and folders in Linux machines in particular. It's the one ... Read More

How are files added to a zip file using Python?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 11-Sep-2023 16:17:00

1K+ Views

An essential skill in the dynamic world of computer programming that is desirable is being able to manage files and archives. The ZIP file is an in−demand archive type that makes data compression and storage simple. Python, which is known for its robustness and adaptability, makes available to developers powerful ... Read More

Would you recommend to define multiple Python classes in a single file?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 09-Sep-2023 23:21:58

3K+ Views

Python is not class-based exclusively - the basic unit of code decomposition in Python is the module. A module is a distinct thing that may have one or two dozen closely-related classes. Modules may as well contain functions along with classes. In Python there is rule of  one module=one file.In ... Read More

How do I declare a global variable in Python class?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 09-Sep-2023 23:21:14

10K+ Views

A global variable is a variable with global scope, meaning that it is visible and accessible throughout the program, unless shadowed. The set of all global variables is known as the global environment or global scope of the program.We declare a variable global by using the keyword global before a ... Read More

How to convert a string to a Python class object?

Rajendra Dharmkar

Rajendra Dharmkar

Updated on 09-Sep-2023 23:15:42

10K+ Views

Given a string as user input to a Python function, I'd like to get a class object out of it if there's a class with that name in the currently defined namespace.Exampleclass Foobar:     pass print eval("Foobar") print type(Foobar)Output __main__.Foobar Another way to convert a string to class ... Read More

Advertisements