str class inheritance prob?
Hamish McKenzie
hamish at valvesoftware.com
Wed Apr 16 14:35:44 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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-list/attachments/20080416/9d6b9960/attachment.html>
More information about the Python-list
mailing list