Python | Technical Handbook

Issue: Search and Replace a word in the file using Python


# Read and save file content
with open('file.txt', 'r') as file :
filedata =
# Replace words with new ones.
filedata = filedata.replace('abc', 'def')
# Overwrite the file with new contents
with open('file.txt', 'w') as file:

Issue: Install virtualenv for Python3


sudo apt-get install python3-pip
sudo pip3 install virtualenv
virtualenv -p python3 myenv
source venv/bin/activate