Linux Debian support - python script assistance

This is Interesting: Free IT Magazines  
Home > Archive > Linux Debian support > May 2007 > python script assistance





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author python script assistance
sk8-365

2007-05-20, 7:13 pm

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 that !).

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.expanduser(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.

And now for the question: can anyone provide the code I need to plug in
to go in sequential order instead?

I'm sure to appreciate it !

Thank you,
--
sk8-365
Tim Johnson

2007-05-20, 7:13 pm

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 that !).
>
> 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.expanduser(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
Tim Johnson

2007-05-20, 7:13 pm

Tim Johnson wrote:

> for file in files:
> do_some_with(file_
>

Typo above: Should have been:
for file in files:
do_some_with(file)
tj
sk8-365

2007-05-20, 7:13 pm

Tim Johnson said:

> Typo above: Should have been:
> for file in files:
> do_some_with(file)


Hi TJ,
Are you saying I can cut and past

for file in files:
do_some_with(file)

into the *.py I posted and get what I desire?
That doesn't seem right tho' , but then again
I'm dense about this Python stuff.

Plus, how is "seed" used? Before "random"? Shall I use that code as
you posted it?

--
sk8-365
Tim Johnson

2007-05-20, 7:13 pm

sk8-365 wrote:
> Tim Johnson said:
>
>
> Hi TJ,
> Are you saying I can cut and past
>
> for file in files:
> do_some_with(file)

Nope.
`do_some_with' is just pseudo-code.
You could do something like this:
for file in files:
print file

> into the *.py I posted and get what I desire?
> That doesn't seem right tho' , but then again
> I'm dense about this Python stuff.
>
> Plus, how is "seed" used? Before "random"? Shall I use that code as
> you posted it?


sure: just put a call random.seed() first.
right after the import statement should work.
the seed() method initializes the number generator.
If you wish to and have the time to learn a little python
the following links should prove useful:

http://www.python.org/doc/ is the URL for Python docs.
http://wiki.python.org/moin/BeginnersGuide could be useful.
http://www.python.org/community/lists/
NOTE: the Python tutor mailing list is *extemely* helpful.
Be aware of Python rules about indentation. If you are using
vim the :set list command is very useful in resolving indentation issues.

I hope this helps. I may have some time later to port this code and
run it if you still have questions.
tim




AJackson

2007-05-23, 7:14 pm

On May 20, 5:23 pm, Tim Johnson <t...@johnsons-web.com> wrote:
> sk8-365 wrote:
>
>
>
>
> Nope.
> `do_some_with' is just pseudo-code.
> You could do something like this:
> for file in files:
> print file
>
>
>
> sure: just put a call random.seed() first.
> right after the import statement should work.
> the seed() method initializes the number generator.
> If you wish to and have the time to learn a little python
> the following links should prove useful:
>
> http://www.python.org/doc/is the URL for Python docs.http://wiki.python.org/moin/BeginnersGuidecould be useful.http://www.python.org/community/lists/
> NOTE: the Python tutor mailing list is *extemely* helpful.
> Be aware of Python rules about indentation. If you are using
> vim the :set list command is very useful in resolving indentation issues.


And in Emacs it intend the code automaticly when you type Enter.
(are the war started now )

Tim Johnson

2007-05-24, 7:13 pm

AJackson wrote:
<...>
>
> And in Emacs it intend the code automaticly when you type Enter.
> (are the war started now )

Not with me... I use emacs/xemacs for coding, and I've written some
elisp functions to help with this issue too.
But I like vim for adhoc editing tasks.
cheers
tim
AJackson

2007-05-29, 1:13 am

On May 24, 12:36 pm, Tim Johnson <t...@johnsons-web.com> wrote:
> AJackson wrote:
>
>
> Not with me... I use emacs/xemacs for coding, and I've written some
> elisp functions to help with this issue too.
> But I like vim for adhoc editing tasks.
> cheers
> tim


Ok, same here. Short configuration file edit with vi and software
devel in Emacs.

Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com