Errors in Python: Syntax, Runtime and Logical
Three kinds of error, found at three different moments. Only one of them can be caught, and the one that catches nobody out is the most dangerous.
968 published notes across every category.
Three kinds of error, found at three different moments. Only one of them can be caught, and the one that catches nobody out is the most dangerous.
try runs risky code, except handles a failure, else runs when nothing failed, and finally always runs. Each block has one job and using the wrong one...
Every exception is a class in one inheritance tree. Catching a parent catches all its children, which is what makes handler order and handler width ma...
raise signals a failure your own code has detected. A custom exception class gives that failure a name callers can catch precisely.
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...