Can I import as only for a function, and have the rest imported as they are?
Let's say I have a function named "hello" in a module named a, and various other functions. Is it possible to import hello as goodbye, along with the other symbols? I am thinking of something like this, however it's not valid:
from a import hello as goodbye开发者_高级运维,*
You can import from a, then bind the new name that you want and delete the previous. Something like
from a import *
goodbye = hello
del hello
Star imports are usually not so good exactly because of namespace pollution.
from a import *
from a import hello as goodbye
from a import *
goodbye = hello
del hello
Would be another way to do it.
Next two lines work fine for me:
from core.commonActions import click_on_toolbar_tool, wait_toolbar_tool_enabled as x
from core.commonActions import wait_toolbar_tool_enabled as x, click_on_toolbar_tool
OR if you need to import all functions you can use:
from core.commonActions import *
from core.commonActions import wait_toolbar_tool_enabled as x
OR:
from core.commonActions import *
x = wait_toolbar_tool_enabled
AND if you want hello not to be more available then simply:
from core.commonActions import *
x = wait_toolbar_tool_enabled
wait_toolbar_tool_enabled = None # or del wait_toolbar_tool_enabled
精彩评论