Skip to content

Instantly share code, notes, and snippets.

@hub-cap
Created February 13, 2014 03:11
Show Gist options
  • Save hub-cap/8969075 to your computer and use it in GitHub Desktop.
Save hub-cap/8969075 to your computer and use it in GitHub Desktop.
>>> def check_portstr(portstr):
... from_port, sep, to_port = portstr.partition('-')
... if not to_port:
... if not sep:
... to_port = from_port
... else:
... raise Exception("onoes")
... return from_port, to_port
...
>>> check_portstr("1-2")
('1', '2')
>>> check_portstr("1")
('1', '1')
>>> check_portstr("1-")
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 7, in check_portstr
Exception: onoes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment