nlp

Natural language processing tutorials covering text analysis and language tasks in Python.

Python: Regex in Practice (Validation, Parsing, Text Processing)

These python regex examples put regular expressions to work on real jobs: validate emails, phone numbers, and passwords, parse log files and CSV (comma-separated values) data, pull clean information out of messy text, and wire it all into a small text processing pipeline. Every pattern here is tested and ready to paste into your own code. “Some people, when faced with a problem, think: I know, I will use regular expressions. Now they have two problems. Use the right tool, ... Read More

Python: Context Managers, with Statement & Custom Managers

A Python context manager is the machinery behind the with statement. This post opens it up so you can see exactly how with works under the hood, what the __enter__ and __exit__ methods do, how to build your own context manager with a class or the @contextmanager decorator, and the patterns that stop resource leaks in real apps. “The cleanup code you never run is the bug you never see coming.” Every developer who has leaked a file handle Last ... Read More

Python: File Handling, Reading and Writing Text Files

Close a program and everything it computed vanishes with it: every variable, every user entry, gone. Python file handling is how a program remembers, by writing data to disk and reading it back on the next run. This guide covers reading, writing, and appending text files with the with statement, plus the mode and encoding choices that quietly decide whether your data survives. “Make it work, make it right, make it fast.” Kent Beck, TDD By Example Last Updated: July ... Read More