Python, from Zero, for AI · Chapter 05
Text that survives the journey
1:43 · Narrated with a synthetic voice. Captions are available in the player.
Read the transcript
Module five is data going in and out, and it takes seriously the fact that most of this audience does not write in English alone. Pass the utf-8 encoding to every file you open, because the platform default is not the same everywhere, and a script that works on one machine writes nonsense on another. When names arrive looking like rubbish, there are two different failures that look identical on screen: text that is intact but was read under the wrong label, which is recoverable in one line, and characters that were replaced by question marks when the file was written, which are gone for good. The module also covers comma separated files, which everybody sends and nobody agrees on, dates and the hour that does not exist, files larger than memory, and virtual environments. It ends with keys. A key is a password that spends your money, so it lives in the environment, never in the source and never in a notebook. If one is ever pushed to a public repository, the order of operations matters more than the speed: revoke first, because that is the only step that stops it working. Rewriting the history afterwards removes the string from the repository and does nothing whatever about the exposure.