losing subclass behavior

Anton Muhin antonmuhin at sendmail.ru
Thu Feb 20 08:45:46 EST 2003


Ian McMeans wrote:
> url = URL("blah")
> url = re.sub('#.*', '', url)

Actually, it is completly expected. Other examples:

x = 3 # Now x is an integer
x = "blah" # Now x is a string

It's all about variables typing that can be changed. As far as I know, 
there is no like __assign__ and it is because of the way Python treats 
variables---they are *refernces* to the objects, not objects themselves. 
  Therefore in most of the cases x = y assigns reference, not the object.

Back to your probelm. I would choose one of the following solutions:

1. Aggregation

class Url:
     ... blah ....
      def setUrl(self, s):
           """Set new string as URL"""

And, sure, you can wrap a string of URL in property.

2. A toolbox (maybe a module) for URL analysis:

protocol(r"http://www.someone.com") ---> "http"

HTH,
Anton.





More information about the Python-list mailing list