What do you want to save?
Add Code snippet
New code examples
-
Python 2022-03-17 02:55:04
Write a python program to find the longest words.
def longestword(filename): with open(filename,'r+') as f: words = f.read().split() max_len_word = max(words,key=len) max_len = len(max(words,key=len)) print('maximum lenth word in file :',max_len_word) print('lenth is : ',max_len) longestwor... Add solution -
Python 2022-03-05 19:00:29
Python Program to Count the Occurrences of a Word in a Text File
#get file object reference to the file file = open("C:\workspace\python\data.txt", "r") #read content of file to string data = file.read() #get number of occurrences of the substring in the string occurrences = data.count("python&... Add solution -
Python 2022-02-18 14:40:06
_pickle.UnpicklingError: the STRING opcode argument must be quoted python
original = "word_data.pkl" destination = "word_data_win10.pkl" content = '' outsize = 0 with open(original, 'rb') as infile: content = infile.read() with open(destination, 'wb') as output: for line in content.splitli... Add solution -
Python 2022-02-04 18:30:17
python replace string in file
# Read in the file with open('file.txt', 'r') as file : filedata = file.read() # Replace the target string filedata = filedata.replace('ram', 'abcd') # Write the file out again with open('file.txt', 'w') as file: file.write(filedata) Add solution -
Python 2022-02-01 12:56:25
website blocker python
#Import libraries import time from datetime import datetime as dt #Windows host file path hostsPath=r"C:\Windows\System32\drivers\etc\hosts" redirect="127.0.0.1" #Add the website you want to block, in this list websites=["www.yout... Add solution -
Python 2022-02-01 00:15:06
python find and replace string in file
# Read in the file with open('file.txt', 'r') as file : filedata = file.read() # Replace the target string filedata = filedata.replace('ram', 'abcd') # Write the file out again with open('file.txt', 'w') as file: file.write(filedata) Add solution
Best helpers
Ranking is empty