with open("Status.txt", "x") as Status: #makes a file
UserName = Status.read() #reads the file
with open("Status.txt", "w") as StatusFileWrite:
StatusFileWrite.write("Hello " + UserName + " :)")
is the code I wrote and it says a error that it can’t read the contents if the file
and how do I change instantly change that the file has when it is created
how do I specify what line it reads
I was ecspecting it to make the string to the contents of the file
this Is the error
UserName = Status.read()
^^^^^^^^^^^^^
io.UnsupportedOperation: not readable
>Solution :
First, write to the file
with open("Status.txt", "w") as StatusFileWrite:
StatusFileWrite.write("Hello User :)")
Now, read from the file
with open("Status.txt", "r") as Status:
UserName = Status.readline() # Reads the first line
print("Read from file:", UserName)