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
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
[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'
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
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
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
>
[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
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
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
[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
[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
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+' ')
12 matches
Mail list logo