[0, 1, 2, 3, 4]>>l1 = range(5)
l2 = range(5,10)
l1
[5, 6, 7, 8, 9]>>l2
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]>>l1.extend(l 2)
l1
good luck.>>
Edwin
-----Original Message-----
From: py************* *************** *************** *******@python. org
[mailto:py****** *************** *************** **************@ python.org]
On Behalf Of Cousin Stanley
Sent: Wednesday, August 13, 2008 10:19 PM
To: py*********@pyt hon.org
Subject: Re: Random Problems
Well the othe day I was making a program to make a listHere's some code .... that illustrates yours ....
of all the songs in certian directorys but I got a problem,
only one of the directorys was added to the list.
....
import glob
songs = glob.glob( '/path/to/somewhere/*.mp3' )
asongs = glob.glob( 'path/to/somewhere/else/*.mp3' )
songs.append( asongs )
# repeat a few times appending lists from other dirs
all goes well but pick awalys is from the first directorysongs.append( asongs ) is appending the entire asongs list
but songs awalys includes all the files I want it to.
as a single item to the end of the songs list, not adding
each individual song as an entry ....
For example ....
[0, 1, 2, 3, 4]>>l1 = range( 0 , 5 )
l2 = range( 5 , 10 )
l3 = range( 11 , 15 )
l1
[5, 6, 7, 8, 9]>>>
l2
[11, 12, 13, 14]>>>
l3
[0, 1, 2, 3, 4, [5, 6, 7, 8, 9]]>>>
l1.append( l2 )
l1
[0, 1, 2, 3, 4, [5, 6, 7, 8, 9], [11, 12, 13, 14]]>>>
l1.append( l3 )
l1
So, if you have a lot of entries in the original songs list
you're only adding a few entries to it in the form of another
list and most likely you didn't run enough random.choice tests
to flush out a pick that turned out to be one of the entire
asong lists that you added ....
You might try something like the following
where each tune gets added individually to
the song pool .... un-tested ....
# -------------------------------------------------------------------
import random
import glob
base_dir = 'c:/Documents and Settings/Admin/My Documents'
list_subdirs = [
'LimeWire/Saved/*.mp3' ,
'Downloads/*/*.mp3' ,
'Downloads/*/*/*.mp3' ,
'Downloads/*/*/*/*.mp3 ]
song_pool = [ ]
for this_dir in list_subdirs :
list_songs = glob.glob( "'%s/%s'" % ( base_dir , this_dir )
if list_songs :
for this_song in list_songs :
song_pool.appen d( this_song )
npicks = 41
for n in range( npicks ) :
this_pick = random.choice( song_pool )
print ' ' , this_pick
# -------------------------------------------------------------------
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
--
http://mail.python.org/mailman/listinfo/python-list
The information contained in this message and any attachment may be
proprietary, confidential, and privileged or subject to the work
product doctrine and thus protected from disclosure. If the reader
of this message is not the intended recipient, or an employee or
agent responsible for delivering this message to the intended
recipient, you are hereby notified that any dissemination,
distribution or copying of this communication is strictly prohibited.
If you have received this communication in error, please notify me
immediately by replying to this message and deleting it and all
copies and backups thereof. Thank you.