473,473 Members | 2,170 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

How you chomp in python

How you cut off the ^M at the end of a line? rstrip is not working.



string.rstrip(build_number)



thanks,



-F






Jul 18 '05 #1
3 41332
"Fernando Armenta" <fa******@pillardata.com> wrote in message news:<ma**********************************@python. org>...
How you cut off the ^M at the end of a line? rstrip is not working.

string.rstrip(build number)

Do you mean the newline character? If your string variable is named
build_number, then

build_number = build_number.rstrip('/n')

works. Sorry if this isn't what you meant. But the format should be
the same. If you did mean ^M then perhaps a hex or octal
representation?
Jul 18 '05 #2
JZ
On Fri, 19 Sep 2003 18:43:14 -0700, "Fernando Armenta"
<fa******@pillardata.com> wrote:
How you cut off the ^M at the end of a line? rstrip is not working.


chomp in Perl change the string in place
rstrip in Python is method, it does NOT change the string in place
s = "abc\n"
s.rstrip() 'abc' s 'abc\n' s = s.rstrip()

'abc'

--
JZ
Jul 18 '05 #3
JZ
On Fri, 19 Sep 2003 18:43:14 -0700, "Fernando Armenta"
<fa******@pillardata.com> wrote:
How you cut off the ^M at the end of a line? rstrip is not working.


Strings in Perl are mutable so chomp() change the string in place.
Strings in Python are *not* mutable, so rstrip() does *not* change
the string in place.
s = "abc\n"
s.rstrip() 'abc' s 'abc\n' s = s.rstrip()

'abc'

--
JZ
Jul 18 '05 #4

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

Similar topics

5
by: Premshree Pillai | last post by:
Hello, I recently wrote a Perl version of pyAlbum.py -- a Python script to create an image album from a given directory -- plAlbum.pl . It made me realize how easy-to-use Python is. ...
9
by: Xah Lee | last post by:
© # -*- coding: utf-8 -*- © # Python © © import sys © © nn = len(sys.argv) © © if not nn==5: © print "error: %s search_text replace_text in_file out_file" % sys.argv
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?
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
20
by: Shawn Milo | last post by:
I'm new to Python and fairly experienced in Perl, although that experience is limited to the things I use daily. I wrote the same script in both Perl and Python, and the output is identical. The...
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...
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...
0
by: Timothy Grant | last post by:
On Fri, Oct 17, 2008 at 3:37 PM, Matt Herzog <msh@blisses.orgwrote: a ',' on the end of your print should suppress the newline. .... print 'foo', .... print 'bar' .... foo bar
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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...
1
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...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.