python white file code example
Example 1: read files and write into another files python
import sys
import glob
import os.path
list_of_files = glob.glob('/Users/Emily/Topics/*.txt')
for file_name in list_of_files:
print(file_name)
f= open(file_name, 'r')
lst = []
for line in f:
line.strip()
line = line.replace("\n" ,'')
line = line.replace("//" , '')
lst.append(line)
f.close()
f=open(os.path.join('/Users/Emily/UpdatedTopics',
os.path.basename(file_name)) , 'w')
for line in lst:
f.write(line)
f.close()
Example 2: python create unreadable save file
import hmac, pickle
pickled = pickle.dumps(data)
digest = hmac.new("some-shared-key", pickled,
digestmod=<my choice of hasher>
).hexdigest()
with open("some-file", "wb") as f:
print(digest, file=f)
print(pickled, file=f)