Tag: python

Python AST: Evaluate an Expression

Do you want to convert a string of Python expression to Python object? Use ast $ cat myast.py import ast exDict = ‘{“name”: “1”}’ x = ast.literal_eval(exDict) print(x) $ python myast.py {‘name’: ‘1’} Another Example >>> import ast >>> x = u'[ “A”,”B”,”C” , ” D”]’ >>> x […]

How to Write a Conference Scheduler

The conference schedule is an NP problem since it is O(2**n). A greedy approach is pragmatic to solve the problem. We can pick various strategies to prepare a schedule such as the biggest talk first, smallest talk first, random selection, etc. The Python code uses the Longest talk […]

Notes on Python Decorator

Notes on Python Decorator Python decorator is a function wrapper. It helps you wrap essential tasks around your functions such as logging, ratelimits, metrics updates etc. However, it has a peculiar behavior due to its dynamic implementation. If you run the following code, what is the expected output? […]

Google App Engine: Data store with async calls

Google Data Store provides single core CPU  (F class) for applications. Hence heavily multi-threaded applications can’t scale enough DataStoreprovidesasync calls for DB access. It has: Async queries Async transactions Async read/writes Documentation is good but lacks clarity on usage and benefits on async calls. It says that async […]