Converting a String to a Boolean in Python

Today, while writing an AWS Lambda function, I needed to read a setting from an environment variable and convert it from a string to a boolean so I could use it in a condition. The obvious guesses are that Python will convert it automatically, or that bool("True") will do the job. But first of all, Python does not do automatic type conversion. This is important! It simply raises an error without any fuss. But surely you’d expect bool() to solve it, right?! In fact, this landmine cost me half an hour today… ...

December 8, 2016 · 1 min

How to Use Python GroupBy on Data (List+Dict)

When working with data in Python, grouping by a certain key is a very common need. For example, when analyzing email logs, you might want to know how many emails were sent for each subject, or list the top five email providers for each subject. In a database, this is very simple. But what if you do not want to send the data to a database? Besides Pandas, the powerful data processing library that can help with this, Python itself also has GroupBy built in! ...

December 7, 2016 · 2 min

What I Saw as an Attendee - PyCon Taiwan 2016

It has been almost a month since PyCon Taiwan 2016. I am very grateful to jserv for the ticket giveaway, which gave me the chance to attend this annual gathering of Taiwanese Python developers. After the event, I kept thinking about what angle to take for this write-up. In the past I mostly worked as a volunteer at community events. This time, since I was an attendee at PyCon, I decided to write a review from the attendee’s point of view, covering the good and the bad things I saw at this year’s PyCon Taiwan. The good parts are worth learning from for other conferences, and the bad parts are worth learning from too, so that they can be improved. ...

June 23, 2016 · 8 min

uWSGI

Introduction uWSGI is a protocol, and it is also a program. Why is it so complicated? Let’s start with the program. uWSGI was originally designed so that web applications written in Python could communicate with web servers such as Nginx and Apache. It uses its own uwsgi communication protocol. It also supports other protocols such as CGI, FastCGI, and sockets, so besides serving Python, it can also integrate with programming languages such as PHP and Go. ...

July 24, 2015 · 8 min

How to Manually Install Python on Linux Without Breaking yum

I previously wrote a program that automatically backs up important data on Linux and uploads it to Google Storage. It was written in Python 2.7, but the Python built into Linux is 2.4, and even if you upgrade with yum, the newest version it gives you is 2.4. So if you want a newer version of Python, you have to compile it yourself. Below, I’ll use Python 3.2 as the example. ...

August 19, 2011 · 2 min

Making Python Module Installation Easier: easy_install Tutorial and Egg File Installation Guide

As everyone knows, one of Python’s key features is its high extensibility. You can install third-party modules to get the functionality you want. For example, if you want to write code in Chinese, you can install the zhpy module. Installing these modules is not especially hard, but it is tedious. Some only need you to click Next a few times, while others require changing system settings. Here I want to introduce a program called “easy_install”, which makes installing modules for Python much simpler. It works similarly to yum on Linux, and with it you only need one command to install a module~ easy_install can also install packages in the so-called egg format. ...

May 1, 2011 · 2 min

[Python] The First Step into the Python World: HelloWorld (Printing Text and Writing Comments)

Almost every programming language book starts with a first practice program, which is Hello World. Hello World means making the program print "HelloWorld". In this article, we will show you how to write your first Python program and briefly explain some basic Python usage....

February 20, 2011 · 2 min

[Python] Python Interpreter Installation Tutorial

Recently I've been playing around with Google Storage, so I dusted off a Python book that had been gathering dust and read through it. Together with the documentation on Google Code, I wrote a small automatic backup program. It's still very simple, so I won't publish it yet. But writing it made me realize that Python is a fairly easy programming language. In terms of ease of learning and rigor, it's about on par with VB. In terms of verbosity, though, Python wins over VB (I mean VB is the wordier one XD). For example, an if statement in VB has to be written as if.....then.......end if, while in Python you just write if....: to get started. Indentation also matters a lot in Python. If the indentation is wrong, the program won't run, because the interpreter uses indentation to decide where selection structures, loops, and so on end. Personally, I'd recommend Python to beginners, since it lets you write very neat code ~...

February 18, 2011 · 3 min