Can Python directory names be keywords? E.g. 'import'?
Am I allowed to have a director开发者_Python百科y named 'import' containing Python code? Or will the import command fail to parse it as a result? Is there any way around that?
You can use the built-in __import__
function which accepts any string. Thus you may write:
__import__('keyword.submodule')
You can have a directory with a name that is a Python keyword storing your Python code. This directory should not be used as a package, since package names should be valid Python identifiers.
Or will the import command fail to parse it as a result?
It will indeed fail.
精彩评论