
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 10492 Articles for Python

1K+ Views
Creating symbolic links (or soft links) in Python can be done using the OS module. A symbolic link is a special type of file that points to another file or directory, allowing you to access it under a different pathname. This can be useful for various reasons, such as creating shortcuts or managing different versions of files. The following methods provide different ways to create symbolic links. Using os.symlink() Function Using pathlib.Path.symlink_to() Function Using Command Line with subprocess Module Using 'os.symlink()' Function The most straightforward way to ... Read More

4K+ Views
Hard links in Python can be created using several methods. Hard links allow you to create multiple names for the same file on the filesystem, meaning changes made to one will reflect in the other. Below are three methods to create hard links. Using os.link() Using os.system() with Shell Command Using subprocess.run() Using 'os.link()' Method The most straightforward way to create a hard link in Python is by using the os.link() method, which is built into the OS module. This method takes two arguments: the source file (`src`) ... Read More

349 Views
You have to use the fdatasync(fd) function to force write of file with filedescriptor fd to disk. It does not force update of metadata. Also note that this is only available on Unix.A more cross platform solution would be to use fsync(fd) as it force write of file with filedescriptor fd to disk. On Unix, this calls the native fsync() function; on Windows, the MS _commit() function.Exampleimport os, sys # Open a file fd = os.open( "foo.txt", os.O_RDWR|os.O_CREAT ) os.write(fd, "This is test") # Now you can use fsync() method. os.fsync(fd) # Now read this file from the beginning os.lseek(fd, ... Read More

2K+ Views
Filesystem information, in Python, is defined as the attributes and metadata linked with a file or directory, such as its name, size, timestamps, permissions, ownership, and type. There are various modules in Python like os and os.path to work with the file system and fetch this information. Obtaining access to filesystem information allows developers to work with files and directories, carry out operations like creation and deletion, and take informed decisions within their code. To fetch file system information using Python, you can utilize the os module; it provides several functions for interacting with the operating system. In particular, the ... Read More

278 Views
To get stat of a file, method stat() from the os module can be used. It performs a stat system call on the given path. For example,import os st = os.stat("file.dat")This function takes the name of a file, and returns a 10-member tuple with the following contents:(mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)The mode variable gives you the information about file permissions. You can get it by st[0].

1K+ Views
We have to realize that in the world of Python programming, obtaining file statistics plays a critical role in processing and manipulating files effectively. It does not matter if you are a novice or an experienced coder; this article will surely guide you through the process of retrieving file stats using Python. By taking a deep dive into the intricacies of file handling and unleashing the potential of Python's built-in functions, we will empower you with the knowledge to effortlessly access valuable statistical data about your files. Understanding File Stats Before we begin exploring the code examples, let us make ... Read More

297 Views
In the realm of Python programming, accessing system configuration information relevant to open files can be very useful in providing valuable insights into the operating environment. It does not matter if you are a curious developer or an avid enthusiast, this article will show you the way through the process of retrieving system configuration details related to open files using Python. By taking advantage of several Python's built-in modules and functions, we will unlock the ability to gather essential information about files in a seamless and efficient manner. We will learn this skill by discussing and practicing several code examples ... Read More

1K+ Views
In Python, duplicates of an existing file are created as backups to manipulate data and to preserve original version. To create a duplicate file of an existing file using Python we can use the shutil module or pathlib module, which we will discuss in detail with examples. Here are the various approaches for this: Creating Duplicate File of an Existing File Using shutil Module Creating Duplicate File of an Existing File Using open() Function Creating Duplicate File of an Existing File Using pathlib Creating Duplicate File ... Read More

6K+ Views
In Python, file-handling tasks like opening, reading, writing, and closing files, or manipulating data in files are a common occurrence. While opening files has its significance and utility, it's equally important that files are closed properly to release system resources and to ensure that data integrity is maintained. In this article, we will explore different methods and techniques to close multiple opened files in Python, permitting you to optimize your file-handling operations and maintain clean code. Making Use of a Context Manager In Python, context managers are a tool for efficiently managing resources that need to be properly ... Read More

1K+ Views
You can use the os.chroot to change the root directory of the current process to path. This command is only available on Unix systems. You can use it as follows:>>> import os >>> os.chroot('/tmp/my_folder')This changes the root directory of the script running to /tmp/my_folder.