Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #77856

Re: Shuffle

Date 2014-09-13 19:32 -0600
From Michael Torrie <torriem@gmail.com>
Subject Re: Shuffle
References <ruk91al1vliuf3uobq1e0el2hrp61p6uf5@4ax.com>
Newsgroups comp.lang.python
Message-ID <mailman.14003.1410658396.18130.python-list@python.org> (permalink)

Show all headers | View raw


On 09/13/2014 05:47 PM, Seymore4Head wrote:
> Here is a screenshot of me trying Dave Briccetti's quiz program from
> the shell and it (the shuffle command) works.
> https://www.youtube.com/watch?v=VR-yNEpGk3g
> http://i.imgur.com/vlpVa5i.jpg
> 
> Two questions
> If you import random, do you need to "from random import shuffle"?
> 
> Why does shuffle work from the command line and not when I add it to
> this program?
> 
> import random
> import shuffle
> nums=list(range(1,11))
> shuffle(nums)
> print (nums)
> 
> I get:
> No module named 'shuffle'

You can do it two ways:
Refer to it as random.shuffle()

or

from random import shuffle

I tend to use the first method (random.shuffle).  That way it prevents
my local namespace from getting polluted with random symbols imported
from modules.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Shuffle Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-13 19:47 -0400
  Re: Shuffle Chris Angelico <rosuav@gmail.com> - 2014-09-14 10:28 +1000
  Re: Shuffle Michael Torrie <torriem@gmail.com> - 2014-09-13 19:32 -0600
    Re: Shuffle Seymore4Head <Seymore4Head@Hotmail.invalid> - 2014-09-13 22:10 -0400
  Re: Shuffle Dave Angel <davea@davea.name> - 2014-09-15 09:32 -0400
    Re: Shuffle Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-09-16 00:02 +1000
      __import__(name, fromlist=...), was Re: Shuffle Peter Otten <__peter__@web.de> - 2014-09-15 16:30 +0200

csiph-web