How does python open a file?
This article is to share with you about how python opens files. The editor thinks it is very practical, so share it with you as a reference and follow the editor to have a look.
Open a file
Returns the file object
In [1]: fo = open ('DDisuza a.txtwriting cognate Modeaux Out ritual, encoding='utf-8') In [2]: fo.read () Out [2]:'\ ufefflife is not so long,\ nI use Python to play.'
Mode value table:
The character meaning'r' reads (default)'w' writes and truncates the exclusive creation of the file'x'. If the file already exists, the write fails. If the file exists, append the'b 'binary mode' t 'text mode (default)' +'to the end for update (read and write)
Thank you for reading! This is the end of the article on "how to open a file in python". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, you can share it out for more people to see!