Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!eternal-september.org!feeder.eternal-september.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed2.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'imported': 0.09; 'namespace': 0.09; 'prevents': 0.09; 'works.': 0.09; 'random': 0.14; '"from': 0.16; 'command)': 0.16; 'from:addr:torriem': 0.16; 'from:name:michael torrie': 0.16; 'modules.': 0.16; 'program?': 0.16; 'symbols': 0.16; 'ways:': 0.16; 'wrote:': 0.18; 'module': 0.19; 'trying': 0.19; '(the': 0.22; 'command': 0.22; 'import': 0.22; 'shell': 0.22; 'print': 0.22; 'header:User-Agent:1': 0.23; 'tend': 0.24; 'header:In-Reply-To:1': 0.27; 'getting': 0.31; 'add': 0.35; 'method': 0.36; 'two': 0.37; 'message-id:@gmail.com': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.39; 'received:org': 0.40; 'dave': 0.60; 'first': 0.61; 'refer': 0.63; 'here': 0.66; 'url:v': 0.71; 'url:youtube': 0.71; 'url:i': 0.72; 'url:watch': 0.77; 'url:jpg': 0.83; 'quiz': 0.84; 'random,': 0.84; 'url:imgur': 0.84 X-Virus-Scanned: amavisd-new at torriefamily.org Date: Sat, 13 Sep 2014 19:32:55 -0600 From: Michael Torrie User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:17.0) Gecko/20131118 Thunderbird/17.0.11 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Shuffle References: In-Reply-To: Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1410658396 news.xs4all.nl 2887 [2001:888:2000:d::a6]:48786 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:77856 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.