Re: file_name_fixer.py

2006-01-25 Thread Steven D'Aprano
On Wed, 25 Jan 2006 10:37:12 +, Richie Hindle wrote: > > [Fredrik] >> so re.sub("([_.])\\1+", "\\1", newname) replaces runs consisting >> of either a . or an _ followed by one or more copies of itself, with >> a single instance of itself. > > ...and this: > def isprime(n): ret

Re: file_name_fixer.py

2006-01-25 Thread Thomas Heller
Richie Hindle <[EMAIL PROTECTED]> writes: > [Fredrik] >> so re.sub("([_.])\\1+", "\\1", newname) replaces runs consisting >> of either a . or an _ followed by one or more copies of itself, with >> a single instance of itself. > > ...and this: > def isprime(n): return n > 1 and not re

Re: file_name_fixer.py

2006-01-25 Thread Richie Hindle
[Fredrik] > so re.sub("([_.])\\1+", "\\1", newname) replaces runs consisting > of either a . or an _ followed by one or more copies of itself, with > a single instance of itself. ...and this: >>> def isprime(n): >>> return n > 1 and not re.match(r'(xx+)\1+$', 'x'*n) finds prime numbers. I'

Re: file_name_fixer.py

2006-01-25 Thread Fredrik Lundh
Steven D'Aprano wrote: > > or you can use a more well-suited function: > > > > # replace runs of _ and . with a single character > > newname = re.sub("_+", "_", newname) > > newname = re.sub("\.+", ".", newname) > > You know, I really must sit down and learn how to use > reg exes one o

Re: file_name_fixer.py

2006-01-25 Thread Steven D'Aprano
Fredrik Lundh wrote: > or you can use a more well-suited function: > > # replace runs of _ and . with a single character > newname = re.sub("_+", "_", newname) > newname = re.sub("\.+", ".", newname) You know, I really must sit down and learn how to use reg exes one of these days. B

Re: file_name_fixer.py

2006-01-25 Thread Fredrik Lundh
Steven D'Aprano wrote: > You should consider factoring out some repeated code > into functions. E.g.: > > # warning: untested!!! > def replace_all(s, old, new): > """Replaces all instances of substring old with > substring new.""" > if old == new: > # make no changes >

Re: file_name_fixer.py

2006-01-25 Thread Steven D'Aprano
[EMAIL PROTECTED] wrote: > i put this together to fix a bunch of files with wierd names, please > gimme feedback, i am a newbie Others have already made comments, here is some more food for thought. You should consider factoring out some repeated code into functions. E.g.: # warning: untested

Re: file_name_fixer.py

2006-01-24 Thread Bruno Desthuilliers
eww a écrit : (top-post corrected) > bruno at modulix wrote: > >>[EMAIL PROTECTED] wrote: >> >>>i put this together to fix a bunch of files with wierd names, please >>>gimme feedback, i am a newbie >> >>Ok, so let's go... Hope you won't hate me too much !-) (snip program and comments) > thanks

Re: file_name_fixer.py

2006-01-24 Thread eww
thanks for the feedback! I'll work on your suggestions. bruno at modulix wrote: > [EMAIL PROTECTED] wrote: > > i put this together to fix a bunch of files with wierd names, please > > gimme feedback, i am a newbie > > Ok, so let's go... Hope you won't hate me too much !-) > > > > > #!/usr/bin/en

Re: file_name_fixer.py

2006-01-24 Thread mdelliot
[EMAIL PROTECTED] wrote: > i put this together to fix a bunch of files with wierd names, please > gimme feedback, i am a newbie See http://aspn.activestate.com/ASPN/Cookbook/Python/Recipe/442517 -- http://mail.python.org/mailman/listinfo/python-list

Re: file_name_fixer.py

2006-01-24 Thread bruno at modulix
[EMAIL PROTECTED] wrote: > i put this together to fix a bunch of files with wierd names, please > gimme feedback, i am a newbie Ok, so let's go... Hope you won't hate me too much !-) > > #!/usr/bin/env python > import os > import sys > import string > import platform > dir = sys.argv[1] This wil

file_name_fixer.py

2006-01-23 Thread ewaguespack
i put this together to fix a bunch of files with wierd names, please gimme feedback, i am a newbie #!/usr/bin/env python import os import sys import string import platform dir = sys.argv[1] noworky = sys.argv[2] if platform.system() == 'Linux': uglychars = ''.join( set(string.punctuation+' ')