Thanks again Justin, ended up with this:
def clean_seperator( self , name ):
"""Replaces seperators within a file name"""
name , ext = os.path.splitext( name )
if ext:
return '.'.join( [ re.sub( r'[^a-zA-Z0-9]+' , self.seperator , name ) ,
ext ] )
else:
return re.sub( r'[^a-zA-Z0-9]+' , self.seperator , name )
much appriciated, I have a couple of issues with doing it that way myself
though, or perhaps it's PEP8 that has more of an issue with it than me...
[1] I'm grabbing the name and extension from a string called name and storing
it in a string called name as well. I've heard different opinions on doing
that but tend to say to myself it's one less string to worry about, once I have
the new name I don't need the old one so to say, as I'm returning a different
representation of the same name I put into the function it makes sense. Keeps
the code cleaner in a way as well to not have multiple names for a name
(newname,thisname,thatname) but I'm quite open for all comments regarding why
not to do this and stick to unique string names in all cases?
[2] I've heard returning the results directly rather than storing something and
then returning that is bad practice but never understood why, for example:
a) (bad?)
def something( path ):
return os.listdir( path )
b) (better?)
def something( path ):
things = os.listdir( path )
return things
--
You received this message because you are subscribed to the Google Groups
"Python Programming for Autodesk Maya" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.