Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

After reading the article referred to by this, I just had to do this. You know that urge ;)

		def osdiscriminator(string):
			good  = "This is a UNIX box and therefore good"
			bad   = "This is a Windows box and therefore bad"
			unkn  = "This is not a box"
			boxes = {"Linux"      : good,
				 "SunOS"      : good,
				 "Windows NT" : bad,
				 "Windows 95" : bad}

			if string in boxes:
				return boxes[string]
			else:
				return unkn
Easy to extend, simple and therefore maintainable without any inheritance or GoF design patterns. Oh, and about one minute of work.

Edit for formatting



A little trick to spare throw more lines:

    return boxes.get(string, unkn)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: