Hacker News new | ask | show | jobs
by hythloday 5258 days ago
I love Lua, but when I read statements like this:

>>> In Python, you might __import__('...')' some module and then the variables of the return value would be accessed like vars(module)

it makes me wonder if the author is just unfamiliar with Python (and by extension, any language other than Lua) or if they're deliberately misrepresenting other languages to make Lua look good (which it definitely doesn't need).

1 comments

Sorry, I would actually consider myself quite proficient in Python. What I was trying to [unsuccessfully] show was that the underlying mechanics of Python's import mechanism are different then, say, Python's dict or list implementations. Whereas in Lua everything really is just a table. I ran into this (in Python) when I was trying to dynamically import code based on command line arguments and access the functions in said script as strings. So in Lua, you just `x = require"script" ; x["fn"]` whereas in Python you sort of need to know this information up front unless you go through the machinations I outlined in the article.

But this was obviously a poorly written part of the article that could use improvement.

[EDIT] typos [EDIT2] less arrogance :)

Hey, thanks for the reply, I do see your point now--I thought you were referring to the usual case of importing modules. It's true that Python modules aren't implemented in terms of dicts or lists and that Python is a larger language than Lua, so I think I completely agree with the point you were making. :)

For future reference, I'd implement your dynamic module importer like this:

  def dynamic_import(name):
       import imp
       return imp.load_module(name, *import.find_module(name))

  os = dynamic_import("os")
Thanks for the pointer! I'll have to keep that in mind.