Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

If you just want to accio act as import, you can always do this:

    accio = __import__
Anyway, interesting article!


Read the article, that was discussed and dismissed. It doesn't make accio 'act as import' because import is a keyword not a function call.


import is a statement. __import__ is a function hence will work.

    In [1]: accio = __import__
    
    In [2]: accio("os")
    Out[2]: <module 'os' from '/usr/lib/python2.7/os.pyc'>


From the article...

    >>> accio = __builtins__.__import__
    >>> accio sys
      File "<stdin>", line 1
        accio sys
                ^
    SyntaxError: invalid syntax
    
    # :(
The author wanted accio to replace import not __import__.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: