All about Python

Cool features and frameworks

Python coroutine - make a generator to coroutine and send data

This artical will talk about generator in Python coroutines. All the demo code below is from http://www.dabeaz.com/coroutines/ . In Python, generator is used to produce a sequence of results. Eve...

Python magic methods (2)

Python magic methods (2) : __call__() In Python, we can call a method using object.method(). Is it possible if we use object() to call a method or do something? __call__() method can help us to ac...

Use awk to parse plain text large file (from DHCP lease for network IP address lookup)

We will always need to use low level tools such as shell script to parse log files or plain text files in linux system. In this example we will show how to use awk command and shell script to parse...

Python magic methods (1) continued - Use magic methods to simplify code in URL matching in Python Pyramid application

In the last article we reviewed the features of python magic methods, __new__() and __init__(). We will look into a real example today about how to use the magic methods to simplify code in Python,...

Python magic methods (1)

Python magic methods (1) : __new__() and __init__() In Python, magic methods are special methods where you can define to add “magic” to classes. They’re always surrounded by double underscores (ca...

Python How to assert a method is called in unit test using Mock/MagicMock

Why do we need unit test? Sometimes developers are asked to restructure their code due to design, framework change or code cleanup purpose. One scenario is, the developer will implement same logic...

Python advanced data structure - collections

Python advanced data structure - collections In Python, dict, list, set and tuple are commonly used data structures. Other than these, Python also has several useful built-in data structures in it...

Serve Python Flask application using mod_wsgi

How to serve Python Flask Application using mod_wsgi-express and Apache in Mac OS X El Capitan If you have a python web application, you will need to deploy it to a physical server after the devel...

Python function - pass by value or by reference?

Python function - pass by value or by reference? Let’s look at below examples to change int number and list in function variables. Changing an int number in function variable def changeNumber(nu...

List Comprehension in Python

List Comprehension in Python - Summary This article is to write tips on what is list comprehension in Python, how to write it, and how to use it. What is Python list comprehension? List comprehe...