Sponsored link Serve your customers, not your servers, with VERIO Linux VPS. Full-access test-drive here. |
PythonPythonPosted Mar 27, 2008 12:43 UTC (Thu) by ernstp (subscriber, #13694)In reply to: yet another +5 by pr1268 Parent article: Striking gold in binutils
Sorry, completely off topic, I just had to post this.
Python:
int( file("foo.txt").read() )
:-P
(Log in to post comments)
Python Posted Mar 27, 2008 13:21 UTC (Thu) by pr1268 (subscriber, #24648) [Link] Show-off! You forgot to catch the exception of the file not opening. Where's your deadParrot() error-handling function? ;-)
Python Posted Mar 27, 2008 17:46 UTC (Thu) by cwarner (subscriber, #47176) [Link] How far we've come.. how far.
Ruby Posted Mar 28, 2008 1:15 UTC (Fri) by Tuxie (subscriber, #47191) [Link]
sorry, I had to :-)
x = File.read("foo.txt").to_i rescue deadParrot
Ruby Posted Mar 28, 2008 16:08 UTC (Fri) by alkandratsenka (subscriber, #50390) [Link]
Reading whole file in memory just to parse int from it's first line is very funny :)
You'll need a longer version like this
(File.open('foo.txt') {|f| f.readline}).to_i rescue deadParrot
|
Copyright © 2008, Eklektix, Inc.
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds
Powered by Rackspace Managed Hosting.