<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Xster.net &#187; print</title>
	<atom:link href="http://tech.xster.net/tag/print/feed/" rel="self" type="application/rss+xml" />
	<link>http://tech.xster.net</link>
	<description>Never relearn twice</description>
	<lastBuildDate>Mon, 30 Aug 2010 00:30:14 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>Python Log Stdout to File</title>
		<link>http://tech.xster.net/tips/python-log-stdout-to-file/</link>
		<comments>http://tech.xster.net/tips/python-log-stdout-to-file/#comments</comments>
		<pubDate>Mon, 30 Nov 2009 18:25:25 +0000</pubDate>
		<dc:creator>xiao</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[file]]></category>
		<category><![CDATA[log]]></category>
		<category><![CDATA[output]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[Python]]></category>
		<category><![CDATA[screen]]></category>
		<category><![CDATA[stdout]]></category>

		<guid isPermaLink="false">http://tech.xster.net/?p=156</guid>
		<description><![CDATA[Python has the ability to alter its sys.stdout as to redirect its print commands to pretty much anything. If, for instance, you want to print to both standard output and to a log file, you can create a class to handle the stdout like such: class MyOutput&#40;&#41;: def __init__&#40;self, logfile&#41;: self.stdout = sys.stdout self.log = [...]]]></description>
			<content:encoded><![CDATA[<p>Python has the ability to alter its sys.stdout as to redirect its print commands to pretty much anything.</p>
<p>If, for instance, you want to print to both standard output and to a log file, you can create a class to handle the stdout like such:</p>

<div class="wp_syntax"><div class="code"><pre class="python" style="font-family:monospace;"><span style="color: #ff7700;font-weight:bold;">class</span> MyOutput<span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>:
    <span style="color: #ff7700;font-weight:bold;">def</span> <span style="color: #0000cd;">__init__</span><span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, logfile<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">stdout</span> = <span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">log</span> = <span style="color: #008000;">open</span><span style="color: black;">&#40;</span>logfile, <span style="color: #483d8b;">'w'</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> write<span style="color: black;">&#40;</span><span style="color: #008000;">self</span>, text<span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">stdout</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">log</span>.<span style="color: black;">write</span><span style="color: black;">&#40;</span>text<span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">log</span>.<span style="color: black;">flush</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
    <span style="color: #ff7700;font-weight:bold;">def</span> close<span style="color: black;">&#40;</span><span style="color: #008000;">self</span><span style="color: black;">&#41;</span>:
        <span style="color: #008000;">self</span>.<span style="color: black;">stdout</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
        <span style="color: #008000;">self</span>.<span style="color: black;">log</span>.<span style="color: black;">close</span><span style="color: black;">&#40;</span><span style="color: black;">&#41;</span>
&nbsp;
<span style="color: #dc143c;">sys</span>.<span style="color: black;">stdout</span> = MyOutput<span style="color: black;">&#40;</span><span style="color: #483d8b;">&quot;log.txt&quot;</span><span style="color: black;">&#41;</span>
<span style="color: #ff7700;font-weight:bold;">print</span> <span style="color: #483d8b;">&quot;blah blah blah&quot;</span></pre></div></div>

<p><span id="more-156"></span><br />
This class would implement stdout&#8217;s write and close functions. We then assign the stdout to an instance of this class. Inside the write/close implementations, we also add functionalities to write the texts in a log file as well. We flush the file buffer on each write because otherwise, we would only be able to see the file content when sys.stdout (therefore MyOutput) closes.</p>
<p>With this, outputs of print will both show in the screen and in the file log.txt</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-spaced">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;title=Python+Log+Stdout+to+File" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;t=Python+Log+Stdout+to+File" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Python+Log+Stdout+to+File+-+http://tech.xster.net/tips/python-log-stdout-to-file/&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-blogger">
			<a href="http://www.blogger.com/blog_this.pyra?t&amp;u=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;n=Python+Log+Stdout+to+File&amp;pli=1" rel="nofollow" class="external" title="Blog this on Blogger">Blog this on Blogger</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;title=Python+Log+Stdout+to+File" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;title=Python+Log+Stdout+to+File" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;t=Python+Log+Stdout+to+File" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;title=Python+Log+Stdout+to+File" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-slashdot">
			<a href="http://slashdot.org/bookmark.pl?url=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;title=Python+Log+Stdout+to+File" rel="nofollow" class="external" title="Submit this to SlashDot">Submit this to SlashDot</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://tech.xster.net/tips/python-log-stdout-to-file/&amp;title=Python+Log+Stdout+to+File&amp;summary=Python%20has%20the%20ability%20to%20alter%20its%20sys.stdout%20as%20to%20redirect%20its%20print%20commands%20to%20pretty%20much%20anything.%0D%0A%0D%0AIf%2C%20for%20instance%2C%20you%20want%20to%20print%20to%20both%20standard%20output%20and%20to%20a%20log%20file%2C%20you%20can%20create%20a%20class%20to%20handle%20the%20stdout%20like%20such%3A%0D%0Aclass%20MyOutput%28%29%3A%0D%0A%20%20%20%20def%20__init__%28self%2C%20logfile%29%3A%0D%0A%20%20%20&amp;source=Xster.net" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://tech.xster.net/tips/python-log-stdout-to-file/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Windows 7 Spooler Continuously Stops on Every Print Action</title>
		<link>http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/</link>
		<comments>http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/#comments</comments>
		<pubDate>Sun, 29 Nov 2009 18:42:55 +0000</pubDate>
		<dc:creator>xiao</dc:creator>
				<category><![CDATA[Tips]]></category>
		<category><![CDATA[Bootcamp]]></category>
		<category><![CDATA[Fusion]]></category>
		<category><![CDATA[Mac]]></category>
		<category><![CDATA[Macbook]]></category>
		<category><![CDATA[print]]></category>
		<category><![CDATA[spooler]]></category>
		<category><![CDATA[ThinPrint]]></category>
		<category><![CDATA[tools]]></category>
		<category><![CDATA[VMWare]]></category>
		<category><![CDATA[Windows]]></category>

		<guid isPermaLink="false">http://tech.xster.net/?p=154</guid>
		<description><![CDATA[Spooler simply stops every time you try to print or add a printer or something? You can keep restarting it but will never be able to print something? I won&#8217;t pretend to know your problem since it depends on potentially so many things but if you have a MacBook, one thing worth investigating is have [...]]]></description>
			<content:encoded><![CDATA[<p>Spooler simply stops every time you try to print or add a printer or something? You can keep restarting it but will never be able to print something? I won&#8217;t pretend to know your problem since it depends on potentially so many things but if you have a MacBook, one thing worth investigating is have you been running VMWare Fusion? The ThinPrint drivers of the VMWare Tools seem to be able to cause this problem when you run the same machine in BootCamp mode. Unfortunately, you can&#8217;t just uninstall it. Uninstalling VMWare Tools from inside virtual mode seems to solve this problem</p>


<div class="shr-bookmarks shr-bookmarks-expand shr-bookmarks-spaced">
<ul class="socials">
		<li class="shr-digg">
			<a href="http://digg.com/submit?phase=2&amp;url=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;title=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action" rel="nofollow" class="external" title="Digg this!">Digg this!</a>
		</li>
		<li class="shr-facebook">
			<a href="http://www.facebook.com/share.php?v=4&amp;src=bm&amp;u=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;t=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action" rel="nofollow" class="external" title="Share this on Facebook">Share this on Facebook</a>
		</li>
		<li class="shr-twitter">
			<a href="http://twitter.com/home?status=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action+-+http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;source=shareaholic" rel="nofollow" class="external" title="Tweet This!">Tweet This!</a>
		</li>
		<li class="shr-blogger">
			<a href="http://www.blogger.com/blog_this.pyra?t&amp;u=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;n=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action&amp;pli=1" rel="nofollow" class="external" title="Blog this on Blogger">Blog this on Blogger</a>
		</li>
		<li class="shr-reddit">
			<a href="http://reddit.com/submit?url=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;title=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action" rel="nofollow" class="external" title="Share this on Reddit">Share this on Reddit</a>
		</li>
		<li class="shr-stumbleupon">
			<a href="http://www.stumbleupon.com/submit?url=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;title=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action" rel="nofollow" class="external" title="Stumble upon something good? Share it on StumbleUpon">Stumble upon something good? Share it on StumbleUpon</a>
		</li>
		<li class="shr-hackernews">
			<a href="http://news.ycombinator.com/submitlink?u=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;t=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action" rel="nofollow" class="external" title="Submit this to Hacker News">Submit this to Hacker News</a>
		</li>
		<li class="shr-delicious">
			<a href="http://delicious.com/post?url=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;title=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action" rel="nofollow" class="external" title="Share this on del.icio.us">Share this on del.icio.us</a>
		</li>
		<li class="shr-slashdot">
			<a href="http://slashdot.org/bookmark.pl?url=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;title=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action" rel="nofollow" class="external" title="Submit this to SlashDot">Submit this to SlashDot</a>
		</li>
		<li class="shr-googlebuzz">
			<a href="http://www.google.com/buzz/post?url=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;imageurl=" rel="nofollow" class="external" title="Post on Google Buzz">Post on Google Buzz</a>
		</li>
		<li class="shr-linkedin">
			<a href="http://www.linkedin.com/shareArticle?mini=true&amp;url=http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/&amp;title=Windows+7+Spooler+Continuously+Stops+on+Every+Print+Action&amp;summary=Spooler%20simply%20stops%20every%20time%20you%20try%20to%20print%20or%20add%20a%20printer%20or%20something%3F%20You%20can%20keep%20restarting%20it%20but%20will%20never%20be%20able%20to%20print%20something%3F%20I%20won%27t%20pretend%20to%20know%20your%20problem%20since%20it%20depends%20on%20potentially%20so%20many%20things%20but%20if%20you%20have%20a%20MacBook%2C%20one%20thing%20worth%20investigating%20is%20have%20y&amp;source=Xster.net" rel="nofollow" class="external" title="Share this on LinkedIn">Share this on LinkedIn</a>
		</li>
</ul>
<div style="clear:both;"></div>
</div>

]]></content:encoded>
			<wfw:commentRss>http://tech.xster.net/tips/windows-7-spooler-continuously-stops-on-every-print-action/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
