Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: chomp?

Reply
Thread Tools

Re: chomp?

 
 
Timothy Grant
Guest
Posts: n/a
 
      10-17-2008
On Fri, Oct 17, 2008 at 3:37 PM, Matt Herzog <(E-Mail Removed)> wrote:
> Hey Pythons.
>
> This script works fine except I would like it to NOT print everything on a newline.
> How can I tell print to chomp?
>
> Thanks.
>
> ------------------------------- snip ---------------------------------------------
> #!/usr/bin/python
> import time
> import sys
>
> def getload():
> f = open('/proc/loadavg')
> data = f.readline()
> f.close()
> (load1, load2, load3, extra) = data.split(' ',3)
> return float(load1)
>
> done = False
> while not done:
> while getload() < 3:
> print getload()
> time.sleep(3)
>
> # we left the loop!
> print "Ouch! My CPUs are roasting!
> time.sleep(3)
>
> --
> "'My country, right or wrong,' is a thing that no patriot would think of saying. It is like saying, 'My mother, drunk or sober.'"
>
> -- G.K. Chesterton
> --
> http://mail.python.org/mailman/listinfo/python-list
>



a ',' on the end of your print should suppress the newline.

>>> def x():

.... print 'foo',
.... print 'bar'
....
>>> x()

foo bar

--
Stand Fast,
tjg. [Timothy Grant]
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments