python script assistance
Web Server forum
Back To The Forum Home!Search!Private Messaging System

Web Server Talk Web Server Talk > Unix and Linux reviews > Free Debian support > Linux Debian support > python script assistance




  Last Thread   Next Thread Next
  Show Printable Version Email this Page Subscribe to this Thread      Post New Thread    Post A Reply      

    python script assistance  
sk8-365


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-21-07 12:13 AM

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





[ Post a follow-up to this message ]



    Re: Python script assistance  
Tim Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
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 ]



    Re: Python script assistance  
Tim Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-21-07 12:13 AM

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





[ Post a follow-up to this message ]



    Re: Python script assistance  
sk8-365


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-21-07 12:13 AM

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





[ Post a follow-up to this message ]



    Re: Python script assistance  
Tim Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-21-07 12:13 AM

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









[ Post a follow-up to this message ]



    Re: Python script assistance  
AJackson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-24-07 12:14 AM

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/BeginnersG
uidecould 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 )






[ Post a follow-up to this message ]



    Re: Python script assistance  
Tim Johnson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-25-07 12:13 AM

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





[ Post a follow-up to this message ]



    Re: Python script assistance  
AJackson


View Ip Address Report This Message To A Moderator Edit/Delete Message


 
05-29-07 06: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.






[ Post a follow-up to this message ]



    Sponsored Links  




 





   All times are GMT. The time now is 03:53 AM.      Post New Thread    Post A Reply      
  Last Thread   Next Thread Next


Most Popular forums 

Forum Jump:
Rate This Thread:

Forum Rules:
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is OFF
vB code is ON
Smilies are ON
[IMG] code is OFF
 
Medical and Health forum | Computer Games Reviews | Graphics design forum

Back To The Top
Home | Usercp | Faq | Register