Reading and Writing Text Files
open() gives you a file object, with reads a file object safely, and four methods cover every text file you will ever process.
A complete core Python path: syntax, data types, operators, strings, control flow, collections, functions, exceptions, files, modules, the standard library, OOP, iterators, generators, decorators, internals, concurrency, regular expressions, testing, typing, performance, security, problem solving, projects, interview preparation and exams.
110 notes in 33 topics
open() gives you a file object, with reads a file object safely, and four methods cover every text file you will ever process.
The mode string decides whether a file is read, written, appended or created, and whether it is treated as text or bytes. The with statement makes any...
Binary mode gives you the raw bytes, and seek and tell let you move around inside a file instead of reading it from start to finish.
pathlib turns file paths into objects with methods. It replaces string joining and most of os.path, and it works the same on Windows, macOS and Linux.
A module is a .py file. import runs it once, caches it, and binds a name. Every import form is a variation on those three steps.
Every module has a __name__. It is "__main__" when the file is run directly and the module name when it is imported, which is what the main guard test...
A package is a directory of modules. __init__.py marks it and defines its public face, and relative imports let modules inside it find each other.
Five standard library modules cover every numeric need core Python has: exact maths, randomness, summary statistics, exact decimals and exact fraction...
datetime handles calendar dates and clock times, timedelta handles durations, strftime and strptime convert to and from text, and time zones are where...
sys is about the running interpreter - arguments, streams, paths and exit. os is about the operating system - environment variables, processes and the...
Six specialised containers that solve problems the built-in types solve awkwardly: counting, grouping, queues, records, and layered lookups.
itertools builds lazy iterators for combining and slicing sequences. functools transforms functions themselves - caching, partial application and redu...