How to open a file using Python?

The key function for working with files in Python is the open() function.

The open() function takes two parameters; filename, and mode.

There are four different methods (modes) for opening a file:

"r" – Read – Default value. Opens a file for reading, error if the file does not exist

"a" – Append – Opens a file for appending, creates the file if it does not exist

"w" – Write – Opens a file for writing, creates the file if it does not exist

"x" – Create – Creates the specified file, returns an error if the file exists

In addition you can specify if the file should be handled as binary or text mode

"t" – Text – Default value. Text mode

"b" – Binary – Binary mode (e.g. images)

[mai mult...]

How to delete an entire word from a file using preg_replace() function in PHP?

preg_replace( $pattern, $replacement, $subject);
Parameters:

$pattern: It contains the string we have to replace.
$replacement: It contains the string that will replace the existing string.
$subject: It contains the main string file where need to remove the string.
We have created a text file named as fruits.txt

mango
apple
papaya
guava
apple
grapes
mango
apple

This program deletes the entire word from the file.

[mai mult...]

How to delete a specific content from a file using preg_replace() function in PHP?

preg_replace( $pattern, $replacement, $subject);
Parameters:

$pattern: It contains the string we have to replace.
$replacement: It contains the string that will replace the existing string.
$subject: It contains the main string file where need to remove the string.
We have created a text file named as fruits.txt

mango
apple
papaya
guava
apple
grapes
mango
apple

This program deletes a specific content from the file using preg_replace() function.

[mai mult...]

How to delete text from a file using preg_replace() function in PHP?

preg_replace( $pattern, $replacement, $subject);
Parameters:

$pattern: It contains the string we have to replace.
$replacement: It contains the string that will replace the existing string.
$subject: It contains the main string file where need to remove the string.
We have created a text file named as fruits.txt

mango
apple
papaya
guava
apple
grapes
mango
apple

This program removes all the strings from the given file.

[mai mult...]

How to Create and Open a File with PHP

In this section, we’ll see how to create and open a file.

When it comes to creating a file, it’s the fopen function which you’ll end up using most of the time. It may seem a bit confusing to use the fopen function to create a file. In fact, the fopen function does two things: it creates a file if it doesn’t exist and also opens it for reading or writing.

Let’s go through the following example to understand how it works.

[mai mult...]

Python – Writing to an excel file using openpyxl module

Openpyxl is a Python library for reading and writing Excel (with extension xlsx/xlsm/xltx/xltm) files. The openpyxl module allows Python program to read and modify Excel files.

For example, user might have to go through thousands of rows and pick out few handful information to make small changes based on some criteria. Using Openpyxl module, these tasks can be done very efficiently and easily.

[mai mult...]