Python alternative to PHP functions