Another question

Mikael Olofsson mikael at isy.liu.se
Mon Apr 17 11:31:30 EDT 2000


On 17-Apr-00 Jeff Massung wrote:
 >  Okay, another quick question. If it is quicker to do:
 >  
 >  
 >  import random
 >  from random import randint
 >  for i in range(1,1000000):
 >      print randint(1,10)
 >  
 >  
 >  than this:
 >  
 >  
 >  import random
 >  for i in range(1,1000000):
 >      print random.randint(1,10)

I'm not the expert here, but I think it's just as quick. Someone may
correct me, though.

 >  Why would I not do "from <module> import *" with every module I load?

Because you may redefine functions if you do

  from <module> import *

If <module> defines its own max(), you loose the original max(). But if
you instead do 

  import <module>

you still have the original max(), and the max() in <module> is called
by 

  <module>.max()

/Mikael

-----------------------------------------------------------------------
E-Mail:  Mikael Olofsson <mikael at isy.liu.se>
WWW:     http://www.dtr.isy.liu.se/dtr/staff/mikael
Phone:   +46 - (0)13 - 28 1343
Telefax: +46 - (0)13 - 28 1339
Date:    17-Apr-00
Time:    17:26:14

This message was sent by XF-Mail.
-----------------------------------------------------------------------



More information about the Python-list mailing list