Dynamic Import with Python
Rewriting my application on Django,
I needed to import classes without knowing their names first
(just reading them out of a directory).
Obviously something like this:1 2
module_name = 'module_foo' import module_name
will just try to import "module_name", and doesn't work the way it's suppose to.
So, what did I do? I solved it by using the__import__
function!
__import__ lets you import modules with parameters given, for instance:1 2 3 4
urllib = __import__(name='urllib') # import urllib</p> <p>#lets say we want "from lxml import etree as tree_module" lxml_module = __import__(name='lxml', fromlist=['etree']) tree_module = lxml_module.etree
Posted in TechnologyBerlin On Feier with a new version
After a long period of developing,
the new version of Berlin On Feier is ready!Posted in TechnologyGoogle Buys Waze
In an expected move (it was almost done a few days ago, and has been in the making),
Google announced it bought Waze.
Waze - The Social GPS App from Israel, has been greatly popular within car drivers, helping people dodge traffic jams,
road blocks, and a lot more, was created at 2008 (which makes it one of the firsts of its kind).Posted in TechnologyGetting Distance between 2 points with MySQL Query
Calculating the distance between 2 points (longitude and latitude) certainly sounds like something that should be solved on the code layer, not on the database layer.Posted in TechnologyDefining custom XPath functions on Python lxml
Parsing with lxml (Python library ) is a very good experience, especially compared to PHP.
An example advantage is that every element found by XPath is once again searchable
(whereas with PHP you can only provide it as a context, but you must provide the DOM ).
However, I came across a case where I needed to split the result to a list (split on python, explode on PHP).Posted in Technology