Tag: python

Why Character Encoding Sucks In Your Language Part 1: Python

Character encoding is one of those topics many software engineers would prefer to have a very minimal understanding of. It's perceived as tricky, uninteresting, and is pretty much an afterthought for most projects that aren't internationalized. This lack of attention leads to tricky bugs that find a way ...


Adding multi-line lambdas to Python

At the risk of this blog becoming dedicated to "the worst things you can do in Python" I present to you: multiline lambdas in Python!

Implementation was simple:

import sys

def fun(string):
    frame = sys._getframe(1)
    out = {}
    locals = {}
    locals.update(frame.f_globals)
    locals.update(frame.f_locals)
    exec ("def __anon ...

Adding functional style pattern matching to Python

One of the nicest features of functional programming languages like Haskell and Erlang is pattern matching. An example, from Learn You Some Erlang:

greet(male, Name) ->
    io:format("Hello, Mr. ~s!", [Name]);
greet(female, Name) ->
    io:format("Hello, Mrs. ~s!", [Name]);
greet(_, Name) ->
    io:format("Hello, ~s!", [Name]).

The ...

© Chad Selph. Built using Pelican. Theme by Giulio Fidente on github. .