Defining our own types?

Michael Yanowitz m.yanowitz at kearfott.com
Wed Aug 16 07:23:38 EDT 2006


Hello:

   I know this will probably turn about to be another dumb question
and I know I have asked a few really dumb ones lately on this list,
but I am hoping otherwise this time:

suppose I type:
ip = 123.45.67.89
  (no quotes)
    - is it possible (maybe by catching an exception), to have this
automatically converted to an ip address and maybe have the exception
convert this into:
  ip = make_ip_address (123, 45, 67, 89)

   Or even better, if possible. Can I define my own type
IP = BYTE + '.' + BYTE + '.' + BYTE + '.' + BYTE
BYTE = in range(256)
  and have Python over-ride its rules so that if I type in a number
followed by a dot followed by number followed by a dot followed by a
number followed by a dot and another number, it can call
make_ip_address() on the value?

Thanks in advance:
Michael Yanowitz





More information about the Python-list mailing list