Reading and Writing Files - Python Tutorial #15

Опубликовано: 28 Апрель 2018
на канале: DMK Data
48
0

The most general way to write and read stuff in python is through the open() function. This function returns us an object that gives us access to a file. Location and name of the file are passed to open() as the first argument. The type and what the object is allowed to do with the file depends on the mode. We can give the mode as a second argument, where certain strings are recognized. 'w' is for write and 'r' is for read. In 'w' mode a file is created if no file exists yet and files are overwritten if a file already exists.

There are several other modes, for example to append more stuff at the end of a file instead of overwriting. In this video we only see how to write strings to files but there is also the option of writing/reading bytes to file. This is a little more complicated because we need to keep track of encoding and decoding, so we need to be aware what the bytes actually mean. In string mode, we also write and read bytes, since everything in a computer is a byte at the end of the day. The encoding for strings is unicode by default. Reading/Writing strings is more seamless and you can get surprisingly far with just strings.

open() documentation:
https://docs.python.org/3/library/fun...


Смотрите видео Reading and Writing Files - Python Tutorial #15 онлайн без регистрации, длительностью часов минут секунд в хорошем качестве. Это видео добавил пользователь DMK Data 28 Апрель 2018, не забудьте поделиться им ссылкой с друзьями и знакомыми, на нашем сайте его посмотрели 48 раз и оно понравилось 0 людям.