Programming 

Python’s Random Module – Everything You Need to Know to Get Started

Life is unpredictable. Sometimes good things happen out of the blue like you find $100 on the floor. And sometimes bad things happen, like your flight being canceled because of bad weather. Most programming languages have a module to deal with randomness. Python is no exception coming with the module named random and in this article, we’ll be looking at the most essential functions you need to use it. The Absolute Basics Before we use any function from the random module, we must import it. import random Because we’re dealing…

Read More

How to Use Gmail to Send an Email with Python’s Yagmail library?

Here’s how you can quickly send an email with Gmail using the Yagmail library: Install Yagmail by running the command pip install yagmail in your shell. Install Keyring by running the command pip install keyring in your shell. Execute the following code snippet (specify your own username, password, and email content): import yagmail yag = yagmail.SMTP(‘username’, ‘password’) yag.send(to = ‘receiver@email.com’, subject = ‘hi’, contents = ‘Just wanted to say “hi”‘) Voilà. You can consult the README to find out about more features such as sending HTML messages.

Read More

I don’t understand Python’s Asyncio

Recently I started looking into Python’s new asyncio module a bit more. The reason for this is that I needed to do something that works better with evented IO and I figured I might give the new hot thing in the Python world a try. Primarily what I learned from this exercise is that I it’s a much more complex system than I expected and I am now at the point where I am very confident that I do not know how to use it properly. It’s not conceptionally hard…

Read More

Be Careful with Python’s New-Style String Format

This should have been obvious to me for a longer time, but until earlier today I did not really realize the severity of the issues caused by str.format on untrusted user input. It came up as a way to bypass the Jinja2 Sandbox in a way that would permit retrieving information that you should not have access to which is why I just pushed out a security release for it. However I think the general issue is quite severe and needs to be a discussed because most people are most…

Read More