• How to create a Windows Service in Python

    Hi guys, today’s post is just for the ones of you that work with the “OS of the misoriented slashes”: Microsoft Windows. 🙂 Have you ever had the need of writing a Python script that could run in background as a Windows Service? In this post you will learn how to do it in less than 10 minutes, no jokes. I…

  • Generators in Python — should I use them?

    Following to a request of a reader, today we’re going to discuss when to use iterators and generators in Python. First of all, it’s important to know what iterators and generators are, so if you don’t know exactly what they are, I suggest to have a look at my previous article on this topic. Now that everything is clear, we…

  • Lambdas and functions in Python

    In my last post I discussed some ways to avoid nested code in Python and discussing the ”filter” and ”map” functions I mentioned the lambda funcions. After that article, some reader asked me to write a little more about this topic, so … here I am. 🙂 Let’s start with a mantra. If you want to know what something is, in Python,…

  • The art of avoiding nested code

    Today’s article is about nested code and how to avoid it. Why we should try to it? Well the answer is inside your heart, and in your Python interpreter… Start your REPL and write: import this you will get the “Zen Of Python” by Tim Peters. The Zen of Python, by Tim Peters Beautiful is better than ugly. Explicit is…

  • Logging in Python

    One of the most underestimated topic that I’ve seen in my working experience is the logs management. A lot of people don’t care at all about logging the execution of their programs and I’ve seen lot of code released in production environment that don’t log anything. To log seems to be a waste of time to them, expecially if the…

  • Writing a FUSE filesystem in Python

    We ran into a problem last week. Our web application produces a lot of documents that have to be accessed frequently for a couple of months after they’re created. However, in less than a year these documents will be almost never accessed anymore, but we need to keep them available for the web application and for tons of other legacy…

  • Working with Exception in Python

    According to the official documentation, an exception is “an error detected during execution not unconditionally fatal”. Let’s start the interpreter and write: >>> 5/0Traceback (most recent call last): File "<pyshell#7>", line 1, in <module> 5/0ZeroDivisionError: division by zero As you can see we asked to the interpreter to divide the number 5 by 0. Even if our request was syntattically…

  • Python Metaclasses

    Working with Python means working with objects because in Python, everything is an object. So, for example: >>> type(1)<class 'int'>>>> type('x')<class 'str'> As you can see, even basic types like integer and strings are objects, in particular they are respectively instances of int and str classes. So, since everything is an object and given that an object is an instance…