Multiple aliases on one-line Python import

2019-02-24 00:28发布

问题:

Can I import module in Python giving it two or more aliases in one line?

With two lines this works:

from time import process_time as tic
from time import process_time as toc

This doesn't work, but I would want to be able to write something like:

from time import process_time as tic,toc

回答1:

You can do that with

from time import process_time as tic, process_time as toc


回答2:

You could do

from time import process_time as tic

toc = tic