str class inheritance prob?
jkazoo at gmail.com
jkazoo at gmail.com
Wed Apr 16 14:43:18 EDT 2008
so I’m trying to create a class that inherits from str, but I want to
run some code on the value on object init. this is what I have:
class Path(str):
def __init__( self, path ):
clean = str(path).replace('\\','/')
while clean.find('//') != -1:
clean = clean.replace('//','/')
print 'cleaned on init:\t',clean
self = clean
so clearly the clean variable is what I want value of the string to
be, but that’s decidedly not the case. so running this:
a=Path('path///with\\nasty/////crap_in_it/')
print a
gives me this:
cleaned on init: path/with/nasty/crap_in_it/
path///with\nasty/////crap_in_it/
what gives? what am I doing wrong, and can I do what I’m trying to
here?
thanks.
More information about the Python-list
mailing list