compress_web.py
Christian Tismer
tismer at tismer.com
Fri Apr 21 15:29:26 EDT 2000
Mike Hostetler wrote:
...
> Email me if you have questions, comments, or sympathies.
Just a few comments.
...
> def compress_web(tar,days,webdir,bad_files):
>
> os.chdir(webdir)
>
> newfiles = []
>
> os.path.walk(webdir,find_time,newfiles)
>
> if (newfiles != []):
It is a common pattern just to ask
if newfiles:
Also, you don't need the braces (probably from using C).
For the next loop, I'd sugest to name the variable
as what it is: a filename, for sure not an "i".
for fname in newfiles:
> for i in newfiles:
> tar = tar+ " " + i
> os.system(tar)
> else:
> print "\n### no files found that needed archived\n"
>
> #####################################
> # this function is called by the os.path.walk for each file in webdir
> def find_time(newfiles, dirname, names):
>
> strlen = len(webdir)+1
> time_limit = time.time() - (86400 * days)
>
> for file in names:
> filename= dirname+"/"+file
>
> # Wow, this line sucks. But it works.
Yes, it sucks, since it is recommended practice to use
filename = os.path.join(dirname, file)
which handles all cases of slashes for you, for all OSes.
Congrats for using Python now, with such success in the first place!
ciao - chris
--
Christian Tismer :^) <mailto:tismer at appliedbiometrics.com>
Applied Biometrics GmbH : Have a break! Take a ride on Python's
Kaunstr. 26 : *Starship* http://starship.python.net
14163 Berlin : PGP key -> http://wwwkeys.pgp.net
PGP Fingerprint E182 71C7 1A9D 66E9 9D15 D3CC D4D7 93E2 1FAE F6DF
where do you want to jump today? http://www.stackless.com
More information about the Python-list
mailing list