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.

1 Comments:

Blogger prathyu said...

dude ..a suggestion, cud u do something abt the font size, seriously very difficult to read even after having spects :)

8:57 PM  

Post a Comment

<< Home



Contact Me: