Is this __import__ functionality correct?

Posted by Jason Baker on Stack Overflow See other posts from Stack Overflow or by Jason Baker
Published on 2010-06-10T18:16:02Z Indexed on 2010/06/10 19:03 UTC
Read the original article Hit count: 239

Filed under:
|
|
|

I have a package named jiva_tasks, which I'm trying to import via celery (using the CELERY_IMPORTS attribute of celeryconfig. The import statement that celery is using is this:

__import__(module, [], [], [''])

Oddly enough, when this syntax is used, the module gets imported twice, once as jiva_tasks and another time as jiva_tasks. (with a period at the end). Now, chances are good that celery should be passing in globals rather than an empty list, but this seems broken to me. It seems odd that even if given the wrong arguments, __import__ would import something that isn't a valid python module name.

I know that the way to fix this is to pass in globals, but I want to understand why I'm getting this result. Is this a bug, or is there something I don't understand about how __import__ is working?

Update: It also seems to be working fine if I use importlib.

© Stack Overflow or respective owner

Related posts about python

Related posts about import