[Frugalware-darcs] vmexam: python/readkey.py: new example

VMiklos vmiklos at frugalware.org
Wed Jun 13 13:33:43 CEST 2007


Darcsweb-Url: http://darcs.frugalware.org/darcsweb/darcsweb.cgi?r=vmexam;a=darcs_commitdiff;h=20070613113208-e2957-2defa5b90817b8b7f6236f588b46eb737d6be601.gz;

[python/readkey.py: new example
VMiklos <vmiklos at frugalware.org>**20070613113208] {
addfile ./python/readkey.py
hunk ./python/readkey.py 1
+import sys, tty, termios
+
+def getc():
+	fd = sys.stdin.fileno()
+	old_settings = termios.tcgetattr(fd)
+	try:
+		tty.setraw(sys.stdin.fileno())
+		c = sys.stdin.read(1)
+	finally:
+		termios.tcsetattr(fd, termios.TCSADRAIN, old_settings)
+	print c
+	return c
+
+sys.stdout.write("yes or no? [y/n]")
+s = getc()
+print "your answer was %s" % s
}


More information about the Frugalware-darcs mailing list