Bio
 
 

Gallery

Blog
 
 

Research


@
Home  
#
Personal  
$
Work  
&
Buttons  
X
Links  

Powered by Blogger

life goes on..... :-) :-( :-|

Thursday, March 02, 2006

weird method of python input / output

I thought i knew every thing about python input/output until i stumbled upon a requirement where i had to print some thing with out a new line character.

I thought sys.out.write() for me to be done with this. Later i realized i can only can send read-only character buffer..or in layman terms if i understood things in a right way should be a string (python programmers correct me if i am wrong)

What do i do. Dumb head !!! what will you do when you don't know an answer for a question. As usual search it on google "how to print without new line character in python". The google answers had a nice link pointing to wiki books. Ahh! now i remember there is something called wiki books which i wanted to have a look at but didn't bother thinking they are not worth looking. Now i decide to see what it has that too on some programming language input output operators. It turned out to be pretty good link (here it is--> http://en.wikibooks.org/wiki/Programming:Python/Input_and_output). Any how it said i could actually use print (which prints anew line character ) by adding a comma at it end.

so print 2, 3
would print as 2 3.
my only problem was i didn't want the white spaces...now how do i that. Thanks to wiki books inspiration i had a nice hack for it. Here it was i did

import sys
for i in range(10,20):
sys.stdout.write('')
print i,

ofcourse, i wouldn't say this is the only and best solution but atleast solves my problem. If any of you readers stumble on my blog and have better answers i am more than obliged to hear you.

Sunday, February 05, 2006

back from hibernation

Even though hari (i forgot to say about this creature...my NERDY roommate) always said that i shouldn't think of coming up with a text specifically for blogs.... rather just write what my experiences were over that day...i realized it only now...so i come back from hibernation....So let me start writing my experiences ...and of course the blog is my diary...what a fool i am ...i didn't realize that.....So what were my experiences today. To start with... today was a fine day. It started with me making a decision that it is high time and i need to apply for summer internships. I could ultimately start doing the applying process after delaying it for a more than a month. I should say it was a success i could write my cover letter for the first time. of course i copied most of the content from some online resource...

One other thing i realized today is i some how don't put much concentration while reading for the first time any form text. I realized that today again....last week i was reading python documentation about readline( ) and raw_input( )...the gist was that readline( ) inserts new line character when it scans for input but raw_input( ) doesn't. even though i read this....i did mistake while coding......i was doing some think like this in my python code

operation = sys.stdin.readline( )
if operation is "1":
....

of course this woudn't work as readline( ) inserts '\n' character and so the if statement should be

if operation is "1\n"
...

now that i realize this my code for interfacing with aardvark...a hardware module which generates i2c signals is complete. All this could happen only because of hari. Thanks to him...i would have killed many precious hours on this stupid thing.



Contact Me: