Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #80422 > unrolled thread

What is rstrip() in python?

Started bysatishmlmlml@gmail.com
First post2014-11-09 03:11 -0800
Last post2014-11-11 11:53 -0800
Articles 7 — 7 participants

Back to article view | Back to comp.lang.python


Contents

  What is rstrip() in python? satishmlmlml@gmail.com - 2014-11-09 03:11 -0800
    Re: What is rstrip() in python? Chris Angelico <rosuav@gmail.com> - 2014-11-09 22:28 +1100
    Re: What is rstrip() in python? Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-11-09 23:57 +1100
    Re: What is rstrip() in python? Mark Lawrence <breamoreboy@yahoo.co.uk> - 2014-11-09 14:17 +0000
    Re: What is rstrip() in python? Terry Reedy <tjreedy@udel.edu> - 2014-11-09 12:46 -0500
    Re: What is rstrip() in python? Joel Goldstick <joel.goldstick@gmail.com> - 2014-11-09 14:16 -0500
    Re: What is rstrip() in python? Will Acheson <willyach07@gmail.com> - 2014-11-11 11:53 -0800

#80422 — What is rstrip() in python?

Fromsatishmlmlml@gmail.com
Date2014-11-09 03:11 -0800
SubjectWhat is rstrip() in python?
Message-ID<c939252e-673b-4cd2-9399-76753a7dd3f7@googlegroups.com>
What is rstrip() in python?

What does it do in the following piece of code?

import sqlite3
conn = sqlite3.connect('dbase1')
curs = conn.cursor()

file = open('data.txt')
rows = [line.rstrip().split(',') for line in file]

[toc] | [next] | [standalone]


#80423

FromChris Angelico <rosuav@gmail.com>
Date2014-11-09 22:28 +1100
Message-ID<mailman.15596.1415532518.18130.python-list@python.org>
In reply to#80422
On Sun, Nov 9, 2014 at 10:11 PM,  <satishmlmlml@gmail.com> wrote:
> What is rstrip() in python?
>
> What does it do in the following piece of code?
>
> import sqlite3
> conn = sqlite3.connect('dbase1')
> curs = conn.cursor()
>
> file = open('data.txt')
> rows = [line.rstrip().split(',') for line in file]

Do you know what type of object 'line' is here? Do you know what you
get when you iterate over a file?

Get an object of that type in the interactive interpreter, maybe like this:

file = open('data.txt')
line = next(file)

Then you can find out about its methods:

help(line.rstrip)

That should tell you what you want to know.

ChrisA

[toc] | [prev] | [next] | [standalone]


#80428

FromSteven D'Aprano <steve+comp.lang.python@pearwood.info>
Date2014-11-09 23:57 +1100
Message-ID<545f64b3$0$12986$c3e8da3$5496439d@news.astraweb.com>
In reply to#80422
satishmlmlml@gmail.com wrote:

> What is rstrip() in python?

Have you read the Fine Manual?

Did you try googling first?

https://duckduckgo.com/html/?q=python+rstrip


> What does it do in the following piece of code?

It removes trailing whitespace.


> import sqlite3
> conn = sqlite3.connect('dbase1')
> curs = conn.cursor()
> 
> file = open('data.txt')
> rows = [line.rstrip().split(',') for line in file]


-- 
Steven

[toc] | [prev] | [next] | [standalone]


#80432

FromMark Lawrence <breamoreboy@yahoo.co.uk>
Date2014-11-09 14:17 +0000
Message-ID<mailman.15600.1415542806.18130.python-list@python.org>
In reply to#80422
On 09/11/2014 11:11, satishmlmlml@gmail.com wrote:
> What is rstrip() in python?

It's a function or method call.

>
> What does it do in the following piece of code?

I'm not actually sure.  Would you be kind enough to look it up in the 
documentation for me and let me know, thanks?

>
> import sqlite3
> conn = sqlite3.connect('dbase1')
> curs = conn.cursor()
>
> file = open('data.txt')
> rows = [line.rstrip().split(',') for line in file]
>

-- 
My fellow Pythonistas, ask not what our language can do for you, ask
what you can do for our language.

Mark Lawrence

[toc] | [prev] | [next] | [standalone]


#80435

FromTerry Reedy <tjreedy@udel.edu>
Date2014-11-09 12:46 -0500
Message-ID<mailman.15603.1415555195.18130.python-list@python.org>
In reply to#80422
On 11/9/2014 6:11 AM, satishmlmlml@gmail.com wrote:
> What is rstrip() in python?

The manuals have a rather complete index.  If 'rstrip' is missing from 
the index, let us know so we can fix it.

-- 
Terry Jan Reedy

[toc] | [prev] | [next] | [standalone]


#80436

FromJoel Goldstick <joel.goldstick@gmail.com>
Date2014-11-09 14:16 -0500
Message-ID<mailman.15604.1415560592.18130.python-list@python.org>
In reply to#80422
On Sun, Nov 9, 2014 at 12:46 PM, Terry Reedy <tjreedy@udel.edu> wrote:
> On 11/9/2014 6:11 AM, satishmlmlml@gmail.com wrote:
>>
>> What is rstrip() in python?

google on 'rstrip python' gets this at first link:
https://docs.python.org/2/library/stdtypes.html#str.rstrip

google is your friend.
>
>
> The manuals have a rather complete index.  If 'rstrip' is missing from the
> index, let us know so we can fix it.
>
> --
> Terry Jan Reedy
>
> --
> https://mail.python.org/mailman/listinfo/python-list



-- 
Joel Goldstick
http://joelgoldstick.com

[toc] | [prev] | [next] | [standalone]


#80554

FromWill Acheson <willyach07@gmail.com>
Date2014-11-11 11:53 -0800
Message-ID<bdee0dc6-bf42-4da2-a411-6d0d8cf1dd39@googlegroups.com>
In reply to#80422
On Sunday, November 9, 2014 6:12:24 AM UTC-5, satish...@gmail.com wrote:
> What is rstrip() in python?
> 
> What does it do in the following piece of code?
> 
> import sqlite3
> conn = sqlite3.connect('dbase1')
> curs = conn.cursor()
> 
> file = open('data.txt')
> rows = [line.rstrip().split(',') for line in file]

rstrip() removes whitespace, newline characters, tab characters, and carrige return characters (\n \t \r respectively) on the tail of a string.  

Or it can be used with an input parameter to remove all instances of that parameter from the tail of a string.

ex:
 stringy = "i am helpful  \t\t\t\t\n\n      "
 stringy = stringy.rstrip()
 print stringy

stdout: "i am helpful"

or:
 stringy = "my favorite number is 8000000000000000000000"
 stringy = stringy.rstrip('0')
 print stringy

stdout: "my favorite number is 8"



pretty simple method, helpful for parsing out formatting characters from scraped content from webpages.
https://docs.python.org/2/library/stdtypes.html?highlight=rstrip#str.rstrip

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web