I'm having a issue with a problem where I want to replace a special character in a text-file that I have created with a string that I defined.
This is a guess the number game.
import datetime, random
from random import randint
fileOpen = open('text.txt','r')
savedData = fileOpen.read()
now = datetime.datetime.now()
date = now.strftime("%Y-%m-%d")
date = str(date)
time = now.strftime("%H:%M")
time = str(time)
Today it's the ; and the time is (. I'm feeling ) and : is todays lucky number. The unlucky number of today is #
str.replace doesn't alter the string in place, no string operations do because strings are immutable. It returns a copy of the replaced string which you need to assign to another name:
replacedData = savedData.replace(";", date)
now your replaced string will be saved to the new name you specified in the assignment.