Author: drweb

I remember the first time I tried to build a Telegram bot. I had a vague idea that it would involve some API and Python, but I kept putting it off because the setup looked complicated. Turns out, it takes about 10 minutes once you know the steps. I am going to walk you through exactly what worked for me. This guide walks you through installing python-telegram-bot, setting up a bot with Telegram’s BotFather, and getting a working bot running on your machine. No fluff, no hand-waving – just the steps that actually work. TLDR Install with pip install python-telegram-bot…

Read More

I keep coming back to the MNIST dataset when I need to quickly test image processing pipelines or validate that a model architecture is actually learning. It is the hello world of machine learning datasets, and after working with it dozens of times I have a workflow that works every time. Let me walk you through exactly how I load and plot the MNIST dataset in Python without running into the common pitfalls. MNIST stands for Modified National Institute of Standards and Technology database. It contains 70,000 square images (28×28 pixels) of handwritten digits from 0 to 9, split into…

Read More

I’ve been working with PyTorch for a while now, and I keep coming back to the same sticking point whenever I start a new project: custom datasets. The built-in datasets are great for learning, but the moment you want to work with your own images, audio files, or any data that doesn’t fit the standard mold, you’re faced with building something from scratch. That’s exactly what I want to walk through in this article. In this tutorial we’ll build custom datasets in PyTorch from the ground up. I’ll show you how to load unlabeled images from a folder, labeled images…

Read More

## TLDR pow(a, n) raises a to the power n – same as a ** n pow(a, n, b) adds modular exponentiation: (a ** n) % b – faster for large numbers The third argument requires a positive exponent – negative exponents with modulus raise a ValueError pow() beats math.pow() for integers – no float conversion, supports modulus, and handles big integers natively Both two-argument and three-argument forms accept any numeric type, including negative exponents and fractions ## How pow() Works in Python ### Two-Argument Form x = pow(2, 5) # 2 raised to the power 5 print(x) # 32…

Read More

I love Python Turtle. Honestly, it’s one of the most fun ways to get started with graphics programming in Python. The module comes built right into Python, so there’s nothing to install before diving in. A virtual turtle acts like a pen, dragging across the screen to carve out shapes and patterns. You can sketch basic polygons, whip up some artwork, or even build simple games and animations. For people just learning to code, having code produce instant visual results makes a huge difference in staying engaged. The idea behind turtle graphics actually goes back to Logo, a programming language…

Read More

I remember when I first heard the term CRUD. It sounded fancy, but honestly it’s just an acronym for four basic operations: Create, Retrieve, Update, and Delete. Any time you build an app that manages data, you’re doing these four things one way or another. Let me break it down quickly. Create puts new records into your database. Retrieve pulls data out. Update modifies existing records. Delete removes them. That’s it. Every blog, every user management system, every inventory tracker works this way. TLDR Flask-SQLAlchemy lets you define database models as Python classes The app uses @app.before_first_request to initialize the…

Read More

Python’s print() function defaults to writing to the console, but it also accepts a file keyword argument that redirects output to any writable file object. This works with any object that has a .write() method — files, io.StringIO, and similar streams. The idiomatic approach pairs print() with a context-managed file handle using with open(…) as f:, which handles closing automatically. Redirecting print() to a file is useful for logging during development, saving script output to disk without modifying program logic, and writing data export pipelines where you want human-readable output. Four common approaches exist, ranging from the recommended print(file=f) pattern…

Read More

Python frozenset() is an immutable version of the built-in set. Once created, a frozenset cannot be modified — elements cannot be added or removed. This immutability makes frozenset hashable, which means it can be used as a dictionary key, stored inside another set, or used anywhere Python expects a hashable object. Regular sets are mutable. They have methods like add(), remove(), and update() that change the set in place. frozenset has none of these mutation methods. The tradeoff is that frozenset gains hashability — the one thing regular sets lack. Understanding when to use each one comes down to whether…

Read More

Pandas makes moving data around straightforward, and ORC has become a reliable choice for analytical workloads. It sits in the same space as Parquet, but ORC offers better compression and solid type preservation. Writing a Pandas DataFrame to ORC takes about three lines of code, and the round-trip is fast enough that it never slows things down. Exactly how to write a DataFrame to ORC, practical examples that go beyond the basics, and the things that trip people up the first few times. At the end, the difference between ORC, Parquet, and CSV is clear, and getting data into ORC…

Read More

I have used linked lists in Python projects for years, and I keep coming back to them when I need fast insertions or deletions in the middle of a collection. Arrays give you O(1) random access, but inserting at position 0 means shifting everything. A linked list sidesteps that entirely. Let me show you how they work and when they actually make sense. In this article, I walk through what linked lists are, how to build one from scratch in Python, and the operations that make them worth using. I have tested each code example against Python 3.12. TLDR Linked…

Read More