use songs.extend( asongs ) #append is for single item - where ever it mightbe.
[0, 1, 2, 3, 4]
[5, 6, 7, 8, 9]
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
good luck.
Edwin
-----Original Message-----
From: python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org
[mailto:python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org]
On Behalf Of Cousin Stanley
Sent: Wednesday, August 13, 2008 10:19 PM
To: python-list@python.org
Subject: Re: Random Problems
Here's some code .... that illustrates yours ....
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
songs.append( asongs ) is appending the entire asongs list
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]
[5, 6, 7, 8, 9]
[11, 12, 13, 14]
[0, 1, 2, 3, 4, [5, 6, 7, 8, 9]]
[0, 1, 2, 3, 4, [5, 6, 7, 8, 9], [11, 12, 13, 14]]
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
print
for n in range( npicks ) :
this_pick = random.choice( song_pool )
print ' ' , this_pick
# -------------------------------------------------------------------
--
Stanley C. Kitching
Human Being
Phoenix, Arizona
--
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.
>>l1 = range(5)
>>l2 = range(5,10)
>>l1
>>l2 = range(5,10)
>>l1
>>l2
>>l1.extend(l 2)
>>l1
>>l1
>>
Edwin
-----Original Message-----
From: python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org
[mailto:python-list-bounces+edwin.m adari=verizonwi reless.com@pyth on.org]
On Behalf Of Cousin Stanley
Sent: Wednesday, August 13, 2008 10:19 PM
To: python-list@python.org
Subject: Re: Random Problems
Well the othe day I was making a program to make a list
of all the songs in certian directorys but I got a problem,
only one of the directorys was added to the list.
....
>
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 directory
but songs awalys includes all the files I want it to.
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 ....
>>l1 = range( 0 , 5 )
>>l2 = range( 5 , 10 )
>>l3 = range( 11 , 15 )
>>>
>>l1
>>l2 = range( 5 , 10 )
>>l3 = range( 11 , 15 )
>>>
>>l1
>>>
>>l2
>>l2
>>>
>>l3
>>l3
>>>
>>l1.append( l2 )
>>>
>>l1
>>l1.append( l2 )
>>>
>>l1
>>>
>>l1.append( l3 )
>>>
>>l1
>>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
--
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.