thing.py

Sign up for a GitHub account Sign in All Gists qpfiffer / thing.py Created June 10, 2015 Code Revisions 2 /.sunken-menu-group /.sunken-menu-contents Embed HTTPS SSH You can clone with HTTPS or SSH . Download Gist /.only-with-full-nav View thing.py thing.py Raw File suppressed. Click to show. 1 2 3 4 5 6 7 8 9 10 # Access elements of a dictionary or a class by string: def get_var_ruby_style ( var , x ): return x[var] if type (x).__name__ == ' dict ' else getattr (x, var) # Return a bound function that always accesses said element, like 'get_var_bound_ruby_style("added_at")' would # always access the "added_at" value of whatever you pass in to it. Hooray closures! def get_var_bound_ruby_style ( var ): def bound_ruby_style ( x ): return...

Linked on 2015-06-10 22:42:40 | Similar Links