05-21-07 12:13 AM
sk8-365 wrote:
> I know nothing of Python scripting and found even less I knew to use
> searching the Web, but likely 'cause I am ignorant about Python coding
> (wouldn't know a Python if it constricted about me - sorry, had to say tha
t !).
>
> Anyhow, I got this off the Net some time ago and have enjoyed the
> randomizer ...
>
> --begin--
> #!/usr/bin/env python
>
> BACKGROUND_DIRS = ['/path/to/images/here/']
> EXTENSIONS = ['jpeg', 'jpg', 'png', 'svg']
>
> import os, glob, random, itertools, gconf
>
> files = list(itertools.chain(*[[os.path.join(dirpath, name)
> for name in filenames]
> for dirpath, dirnames, filenames in
> itertools.chain(*[os.walk(os.path.expan
duser(d))
> for d in BACKGROUND_DIRS]
)]))
> gconf.client_get_default().set_string(
> '/desktop/gnome/background/picture_filename',
> random.choice(files))
>
> --end--
>
> ... thing is I see some of the images much of the time and others
> never - there are 1709 images in one folder alone but I see 20 or so
> of them only.
Hi:
I never use random.choice() without first calling random.seed()
> And now for the question: can anyone provide the code I need to plug in
> to go in sequential order instead?
Generally to do this you would do something like this:
for file in files:
do_some_with(file_
## <grin> If I weren't spending so much time scr*wing with ubuntu, I'd
## have more time for this </grin>
## Tim
[ Post a follow-up to this message ]
|