Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread Luke Paireepinart
Oops, you should probably have a "return True" at the end of the function so the return value is meaningful. On Tue, Jul 7, 2009 at 9:29 PM, Luke Paireepinart wrote: > I typically abuse the fact that "return" will get you out of a function to > make my code indented less.perhaps others would frown

Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread Luke Paireepinart
I typically abuse the fact that "return" will get you out of a function to make my code indented less.perhaps others would frown upon this but it makes sense to me. With various other changes, I'd make your function like so: from os import path, listdir, remove def clean(folder): if not path.e

Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread David
Luke Paireepinart wrote: On Tue, Jul 7, 2009 at 8:36 PM, David > wrote: Hi Tutors, Hiya david. Cool e-mail address :) Thanks, want l...@pythontoo.com I have a few to spare :) But if there are no files in the directory it never gets to the else. Rig

Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread Marc Tompkins
On Tue, Jul 7, 2009 at 6:36 PM, David wrote: > My question is I tried to get it to print out when the directory was empty > like this; > > for file in fobj: >pathname = os.path.join(folder, file) >if os.path.exists(pathname): >print 'removing... ', file >os.remove(pathname

Re: [Tutor] if: else: can not get else to work

2009-07-07 Thread Luke Paireepinart
On Tue, Jul 7, 2009 at 8:36 PM, David wrote: > Hi Tutors, Hiya david. Cool e-mail address :) > My question is I tried to get it to print out when the directory was empty > like this; > > for file in fobj: >pathname = os.path.join(folder, file) >if os.path.exists(pathname): >pri

[Tutor] if: else: can not get else to work

2009-07-07 Thread David
Hi Tutors, I have a web cam that saves files in /var/log/motion and it can get quite large so I clean it every few days. I came up with this; #!/usr/bin/python import commands import os from sys import exit def clean_motion(): folder = '/var/log/motion' if os.path.exists(folder):