Hello, I am unsure how exactly to do this section, i only get one change once i
ID: 3733989 • Letter: H
Question
Hello, I am unsure how exactly to do this section, i only get one change once i submit my answer that is it i cannot change it. i am using Codio/Python
4.4. Writing a text file Writing a Text File Submit Answer You can write the contents of a variable out to a file, all at once, like this: 7 # open our fila for uriting 10 #krita "text", to the fi(a at ,filapath 11 file1.rite(taxt) 12 file1.close) Notice that the file was opened with the option, which tells the system to write to the file. Also note that the we closed the file. To read the contents of the file that was just written, open the file again for reading with theoption this time at line 15 14 # print out tha contants of tha fit 15 fila1 apan(Filapath. 'r' 16 print(fila1.read)) 17 fila1.closs) RUN THE WRITE SAMPLEExplanation / Answer
# prepare variables filepath = 'file.txt' text = 'hello, how are you?' # write to file file1 = open(filepath, 'w') file1.write(text) file1.close() # read from file file1 = open(filepath, 'r') print(file1.read()) file1.close()
Related Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.