[Tutor] New to list & first steps in Python
alan.gauld at blueyonder.co.uk
Sat Jun 5 18:03:57 EDT 2004
> > from random import choice
> > ###
> What I've been doing lately in cases like this is:
> import random
> x = random.choice( y )
> What do you other experienced Pythonistas think of that style?
Its the preferred one at the cost of extra typing. Using this approach
is safest, ythere is no possibility of accidentally importing another
coice and hiding the "random" one. Only if you will use it a lot and
know there will never be conflict would I recommend the first option.
Even if the typing is too much you can reduce it with
import random as r
That still keeps it safe (unless you import another module called
r or as r I guess!)
> I admit that I don't like the length it adds to my lines of code,
but I do
> like that it's clear and easy to see which module each function came
That about sums up the pros and cons.
More information about the Tutor