Welcome to the CSC Q&A, on our server named in honor of Ada Lovelace. Write great code! Get help and give help!
It is our choices... that show what we truly are, far more than our abilities.

Categories

+7 votes

Hi,
I wanted to ask does anyone know, why does thonny read file if you write 'r' after the file like in class professor showed to read the file or to put it in reading mode you need to do this:
file = open('rooster.txt', 'r')
but why does it do that from 'r' it you see do this to anything else it just prints out r?
And same for writing the file 'w'

Please let me know!!

Thank you in advance!!!

asked in CSC201 Spring 2021 by (1 point)

1 Answer

+2 votes
 
Best answer

Opening and reading files are different operations.

A file is opened as a first step in reading from it or writing to it. By default, the open() call accesses the file in read mode. Specifying 'r' as the second argument is just doing the same thing. (Specifying 'w' opens the file in write mode.)

answered by (1 point)
selected by
0

Ohh! Makes sense now!
Thank you so much for help!! I was confused on it! that makes sense now!

+1

Haha you're welcome buddy!

...