473,407 Members | 2,676 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,407 software developers and data experts.

Re: chomp?

On Fri, Oct 17, 2008 at 3:37 PM, Matt Herzog <ms*@blisses.orgwrote:
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]
Oct 17 '08 #1
0 970

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Fernando Armenta | last post by:
How you cut off the ^M at the end of a line? rstrip is not working. string.rstrip(build_number) thanks,
0
by: Aaron Powell | last post by:
I am writing a program for a study I am doing where I must contact several different organisations stored in a database I compiled, but I need to send each email one at a time so they don't know...
2
by: Matt Taylor | last post by:
I have this piece of code: $/ = ' '; $test = "abc "; chomp $test; print $test; which prints spaces at the end of the line. Shouldn't chomp strip the spaces off the end of my scalar $test?
2
by: perl_begi | last post by:
I am having a file that contains different strings, which in turn are name of folders. For example test. file has: test0002 intel/drivers/ Here there can be spaces, tabs after folder names...
35
by: lnatz | last post by:
Hi, Is there an equivalent to the perl command chomp in C? And if there is no exact equivalent command, how would I go about removing the "\n" at the end of a stdin? Thank you, Natalie
1
by: mrmattborja | last post by:
I have the following lines in a simple for() loop: time_t rightnow; (void) time(&rightnow); fprintf(fp, " waited for pass %d to finish", asctime(localtime(&rightnow)), i) However, when I pull...
3
by: adriaan | last post by:
I'm having this weird problem with chomp I want to get all the numbers out of a file that looks like this 1,2 4,3,2 and have the first number point to an array of the others in a hash I'm almost...
5
by: Beany | last post by:
Hi, Probably a very simple question for the experienced Perl programmers.... Im new to the language of Perl and at the moment im studying the function Chomp! for some strange reason i cant...
0
by: Matt Herzog | last post by:
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...
4
by: ezechiel | last post by:
Hi, while testing the program (runs in DOS), I thought "if someone hits enter without typing a letter before, what happens?" I tested and the script ends.. Is this normal, or how can I avoid this?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.