Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

django - changing import name in python

is it possible to change the name of the imported python file?

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)
     ...

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 ...

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?

thanks in advance ...

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...