改变python中的导入名称 [英] changing import name in python
问题描述
可以更改导入的python文件的名称吗?
is it possible to change the name of the imported python file?
在我的views.py在django我有
in my views.py in django i have
from myapp.models import *
from suds.client import Client
def main_page(request, id):
client = Client.objects.get(id=id)
...
response = Client(WSDL_FILE)
...
在我的模型中,我有一个客户端的模型,但是当我使用 suds
为 WSDL
文件,
i import客户端,但我的客户端模型中有AttributeError ...
in my models i have a model of a Client, but when i used suds
for the WSDL
file,
i import Client but i got the AttributeError in my Client's model ...
我的问题是,它如果我可以在 suds.client
中更改客户端
的名称是可能的。
my question is, it is possible if i can change the name of the Client
in suds.client
?
任何人都可以了解我的情况?
can anyone have an idea about my situation?
提前感谢...
推荐答案
是的,您可以使用作为
关键字。
Yes, you can use as
keyword.
import my_module as some_other_name
from suds.client import Client as Spam
正是为此目的。这在这里的文档中有所解释:
It's for exactly this purpose. This is explained in the docs here:
http://docs.python.org/reference/simple_stmts.html#import
这篇关于改变python中的导入名称的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!