<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DZone Snippets: stdin code</title>
    <link>http://snippets.dzone.com/posts</link>
    <pubDate>Sun, 18 May 2008 00:27:42 GMT</pubDate>
    <description>DZone Snippets: stdin code</description>
    <item>
      <title>Python - getchar()</title>
      <link>http://snippets.dzone.com/posts/show/3084</link>
      <description>&lt;code&gt;&lt;br /&gt;import os,sys&lt;br /&gt;import sys&lt;br /&gt;import termios&lt;br /&gt;&lt;br /&gt;def getchar():&lt;br /&gt;	'''&lt;br /&gt;	Equivale al comando getchar() di C&lt;br /&gt;	'''&lt;br /&gt;&lt;br /&gt;	fd = sys.stdin.fileno()&lt;br /&gt;	&lt;br /&gt;	if os.isatty(fd):&lt;br /&gt;		&lt;br /&gt;		old = termios.tcgetattr(fd)&lt;br /&gt;		new = termios.tcgetattr(fd)&lt;br /&gt;		new[3] = new[3] &amp; ~termios.ICANON &amp; ~termios.ECHO&lt;br /&gt;		new[6] [termios.VMIN] = 1&lt;br /&gt;		new[6] [termios.VTIME] = 0&lt;br /&gt;		&lt;br /&gt;		try:&lt;br /&gt;			termios.tcsetattr(fd, termios.TCSANOW, new)&lt;br /&gt;			termios.tcsendbreak(fd,0)&lt;br /&gt;			ch = os.read(fd,7)&lt;br /&gt;&lt;br /&gt;		finally:&lt;br /&gt;			termios.tcsetattr(fd, termios.TCSAFLUSH, old)&lt;br /&gt;	else:&lt;br /&gt;		ch = os.read(fd,7)&lt;br /&gt;	&lt;br /&gt;	return(ch)&lt;br /&gt;&lt;/code&gt;</description>
      <pubDate>Tue, 05 Dec 2006 16:16:53 GMT</pubDate>
      <guid>http://snippets.dzone.com/posts/show/3084</guid>
      <author>whitetiger ()</author>
    </item>
  </channel>
</rss>
