Re: chomp?

Discussion in 'Python' started by Timothy Grant, Oct 18, 2008.

  1. On Fri, Oct 17, 2008 at 3:37 PM, Matt Herzog <> 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]
    Timothy Grant, Oct 18, 2008
    #1
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Aaron Powell
    Replies:
    0
    Views:
    1,186
    Aaron Powell
    Jul 24, 2003
  2. Matt Taylor

    Question on Chomp

    Matt Taylor, Sep 29, 2003, in forum: Perl
    Replies:
    2
    Views:
    372
    Matt Taylor
    Sep 29, 2003
  3. Fernando Armenta

    How you chomp in python

    Fernando Armenta, Sep 20, 2003, in forum: Python
    Replies:
    3
    Views:
    8,536
  4. Jeremy Dillworth

    Re: How you chomp in python

    Jeremy Dillworth, Sep 20, 2003, in forum: Python
    Replies:
    0
    Views:
    950
    Jeremy Dillworth
    Sep 20, 2003
  5. martin
    Replies:
    3
    Views:
    166
    Joe Smith
    Apr 15, 2006
Loading...

Share This Page