<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	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/"
		>
<channel>
	<title>Comments on: Python: Uptime script</title>
	<atom:link href="http://thesmithfam.org/blog/2005/11/19/python-uptime-script/feed/" rel="self" type="application/rss+xml" />
	<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/</link>
	<description>Your blog is probably better than mine.</description>
	<lastBuildDate>Sun, 05 Feb 2012 05:18:10 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
	<item>
		<title>By: Dave</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-152295</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Sat, 29 Oct 2011 17:28:56 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-152295</guid>
		<description>Aryeh, thanks for the info. Cool news about the new ternary operator in Python 2.5.</description>
		<content:encoded><![CDATA[<p>Aryeh, thanks for the info. Cool news about the new ternary operator in Python 2.5.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Aryeh Leib Taurog</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-152294</link>
		<dc:creator>Aryeh Leib Taurog</dc:creator>
		<pubDate>Sat, 29 Oct 2011 17:25:08 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-152294</guid>
		<description>@Mauro don&#039;t use fromtimestamp, because that is a calendar date which starts at 2am 1970-01-01 and wraps back around to 1 at the beginning of each month, so your day and your hour will always be off.

All we really need is:

import datetime
with open(&#039;/proc/uptime&#039;) as f:
   uptime, idletime = map(float, f.read().split())

print(datetime.timedelta(seconds=uptime))

@Dave python does have a ternary operator
http://docs.python.org/reference/expressions.html#conditional-expressions</description>
		<content:encoded><![CDATA[<p>@Mauro don&#8217;t use fromtimestamp, because that is a calendar date which starts at 2am 1970-01-01 and wraps back around to 1 at the beginning of each month, so your day and your hour will always be off.</p>
<p>All we really need is:</p>
<p>import datetime<br />
with open(&#8216;/proc/uptime&#8217;) as f:<br />
   uptime, idletime = map(float, f.read().split())</p>
<p>print(datetime.timedelta(seconds=uptime))</p>
<p>@Dave python does have a ternary operator<br />
<a href="http://docs.python.org/reference/expressions.html#conditional-expressions" rel="nofollow">http://docs.python.org/reference/expressions.html#conditional-expressions</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Squeezemynutz</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-136582</link>
		<dc:creator>Squeezemynutz</dc:creator>
		<pubDate>Thu, 09 Jun 2011 18:31:35 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-136582</guid>
		<description>@Mauro Baraldi: Script does not display the day correctly, on my Debian box it&#039;s had an uptime of 66 days, your script says 6.</description>
		<content:encoded><![CDATA[<p>@Mauro Baraldi: Script does not display the day correctly, on my Debian box it&#8217;s had an uptime of 66 days, your script says 6.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Mauro Baraldi</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-120611</link>
		<dc:creator>Mauro Baraldi</dc:creator>
		<pubDate>Tue, 04 Jan 2011 13:23:14 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-120611</guid>
		<description>Hello Dave,

Your script is really very usefull, but I refactored it. I used datetime lib to simplify handle with time.

Here is the result: http://pastebin.com/Tks3Rnst

Anyway thanks for the inspiration ;-)

Greeting from Brazil!!</description>
		<content:encoded><![CDATA[<p>Hello Dave,</p>
<p>Your script is really very usefull, but I refactored it. I used datetime lib to simplify handle with time.</p>
<p>Here is the result: <a href="http://pastebin.com/Tks3Rnst" rel="nofollow">http://pastebin.com/Tks3Rnst</a></p>
<p>Anyway thanks for the inspiration ;-)</p>
<p>Greeting from Brazil!!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Anonymous</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-120610</link>
		<dc:creator>Anonymous</dc:creator>
		<pubDate>Tue, 04 Jan 2011 13:21:52 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-120610</guid>
		<description>Hello Dave,

Your script is really very usefull, but I refactored it. I used datetime lib to simplify handle with time.

Here is the result: http://pastebin.com/Tks3Rnst

Anyway thanks for the inspiration ;-)</description>
		<content:encoded><![CDATA[<p>Hello Dave,</p>
<p>Your script is really very usefull, but I refactored it. I used datetime lib to simplify handle with time.</p>
<p>Here is the result: <a href="http://pastebin.com/Tks3Rnst" rel="nofollow">http://pastebin.com/Tks3Rnst</a></p>
<p>Anyway thanks for the inspiration ;-)</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Tim</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-102836</link>
		<dc:creator>Tim</dc:creator>
		<pubDate>Sat, 05 Jun 2010 09:09:29 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-102836</guid>
		<description>Brilliant little script - thanks!

Despite your earlier comment, I think this is useful as a stand-alone script. The problem with the &#039;uptime&#039; command is that is outputs other junk as well as the system uptime, and because this output is so variable depending on how long the system has been up, parsing it to extract only the uptime is non-trivial. 

If you want just the system uptime, and nothing more, your script does the business!</description>
		<content:encoded><![CDATA[<p>Brilliant little script &#8211; thanks!</p>
<p>Despite your earlier comment, I think this is useful as a stand-alone script. The problem with the &#8216;uptime&#8217; command is that is outputs other junk as well as the system uptime, and because this output is so variable depending on how long the system has been up, parsing it to extract only the uptime is non-trivial. </p>
<p>If you want just the system uptime, and nothing more, your script does the business!</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Zemair</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-102020</link>
		<dc:creator>Zemair</dc:creator>
		<pubDate>Mon, 10 May 2010 03:27:48 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-102020</guid>
		<description>(sorry my bad english)

Hi Dave! Great script! Thanks for the code!

I want contribute! To work on FreeBSD 6.x and FreeBSD 7.x, replace lines 9, 10, 11 and 13 with follow lines:

[line 9] varOutPut = commands.getoutput(&quot;/sbin/sysctl kern.boottime &#124; /usr/bin/awk &#039;{ print $5 \&quot;.\&quot; $8   }&#039;&quot;)

[line 10] varOutPut = varOutPut.split(&quot;,&quot;)

[line 11] total_seconds = time.time() - float(varOutPut[0])

[line 13] &quot;Cannot request kernel variable&quot;

Also import &quot;commands&quot; to proper work the getoutput method.</description>
		<content:encoded><![CDATA[<p>(sorry my bad english)</p>
<p>Hi Dave! Great script! Thanks for the code!</p>
<p>I want contribute! To work on FreeBSD 6.x and FreeBSD 7.x, replace lines 9, 10, 11 and 13 with follow lines:</p>
<p>[line 9] varOutPut = commands.getoutput(&#8220;/sbin/sysctl kern.boottime | /usr/bin/awk &#8216;{ print $5 \&#8221;.\&#8221; $8   }&#8217;&#8221;)</p>
<p>[line 10] varOutPut = varOutPut.split(&#8220;,&#8221;)</p>
<p>[line 11] total_seconds = time.time() &#8211; float(varOutPut[0])</p>
<p>[line 13] &#8220;Cannot request kernel variable&#8221;</p>
<p>Also import &#8220;commands&#8221; to proper work the getoutput method.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: trash80</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-83128</link>
		<dc:creator>trash80</dc:creator>
		<pubDate>Wed, 22 Jul 2009 17:31:49 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-83128</guid>
		<description>Great script.  Nice to see others that also prefer readable code over obfuscated, complex one liners.  I&#039;m not big on ternaries, but this seems alright.  Thanks for the script.</description>
		<content:encoded><![CDATA[<p>Great script.  Nice to see others that also prefer readable code over obfuscated, complex one liners.  I&#8217;m not big on ternaries, but this seems alright.  Thanks for the script.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Dave</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-67569</link>
		<dc:creator>Dave</dc:creator>
		<pubDate>Thu, 18 Dec 2008 13:06:28 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-67569</guid>
		<description>What about the case of 0 days? Your code will show &quot;0 day&quot;, but I would prefer &quot;0 days&quot;.

I think the version with the ternary operator is actually more readable than two separate lines.</description>
		<content:encoded><![CDATA[<p>What about the case of 0 days? Your code will show &#8220;0 day&#8221;, but I would prefer &#8220;0 days&#8221;.</p>
<p>I think the version with the ternary operator is actually more readable than two separate lines.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Iñaki Silanes</title>
		<link>http://thesmithfam.org/blog/2005/11/19/python-uptime-script/comment-page-1/#comment-67562</link>
		<dc:creator>Iñaki Silanes</dc:creator>
		<pubDate>Thu, 18 Dec 2008 12:08:28 +0000</pubDate>
		<guid isPermaLink="false">http://thesmithfam.org/blog/?p=8#comment-67562</guid>
		<description>The ternary operator is nice, but detrimental to readability. You can substitute:

string += str(days) + &quot; &quot; + (days == 1 and &quot;day&quot; or &quot;days&quot; )

with the more readable (and equally short):

string += str(days) + &#039; day&#039;
if days &gt; 1:  string += &#039;s&#039;</description>
		<content:encoded><![CDATA[<p>The ternary operator is nice, but detrimental to readability. You can substitute:</p>
<p>string += str(days) + &#8221; &#8221; + (days == 1 and &#8220;day&#8221; or &#8220;days&#8221; )</p>
<p>with the more readable (and equally short):</p>
<p>string += str(days) + &#8216; day&#8217;<br />
if days &gt; 1:  string += &#8216;s&#8217;</p>
]]></content:encoded>
	</item>
</channel>
</rss>

