Never been to DZone Snippets before?

Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

About this user

« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS 

Python - getchar()

   1  
   2  import os,sys
   3  import sys
   4  import termios
   5  
   6  def getchar():
   7  	'''
   8  	Equivale al comando getchar() di C
   9  	'''
  10  
  11  	fd = sys.stdin.fileno()
  12  	
  13  	if os.isatty(fd):
  14  		
  15  		old = termios.tcgetattr(fd)
  16  		new = termios.tcgetattr(fd)
  17  		new[3] = new[3] & ~termios.ICANON & ~termios.ECHO
  18  		new[6] [termios.VMIN] = 1
  19  		new[6] [termios.VTIME] = 0
  20  		
  21  		try:
  22  			termios.tcsetattr(fd, termios.TCSANOW, new)
  23  			termios.tcsendbreak(fd,0)
  24  			ch = os.read(fd,7)
  25  
  26  		finally:
  27  			termios.tcsetattr(fd, termios.TCSAFLUSH, old)
  28  	else:
  29  		ch = os.read(fd,7)
  30  	
  31  	return(ch)
« Newer Snippets
Older Snippets »
Showing 1-1 of 1 total  RSS