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


Groups > comp.lang.python > #22047

RE: Odd strip behavior

From "Prasad, Ramit" <ramit.prasad@jpmorgan.com>
Subject RE: Odd strip behavior
Date 2012-03-22 19:54 +0000
References <5B2CBFB0-DC2D-47E1-978F-59E47EB3A757@gmail.com>
Newsgroups comp.lang.python
Message-ID <mailman.906.1332446094.3037.python-list@python.org> (permalink)

Show all headers | View raw


>     str1='this is a test'
>     str2='t'
> 
>     print "".join([ c for c in str1 if c not in str2 ])
>     print(str1.strip(str2))
> 
> if __name__ == '__main__':
>     main()
> 
> ./remove_str.py
> his is a es
> his is a tes
> 
> Why wasnt the t removed ?

This is not odd behavior, you just do not understand what
strip does. :)

The behavior is listed on the API. I highly recommend you 
take time to become familiar with it. 


http://docs.python.org/library/stdtypes.html#string-methods
str.strip([chars])
    Return a copy of the string with the leading and trailing characters removed. The chars argument is a string specifying the set of characters to be removed. If omitted or None, the chars argument defaults to removing whitespace. The chars argument is not a prefix or suffix; rather, all combinations of its values are stripped:
    >>>
    >>> '   spacious   '.strip()
    'spacious'
    >>> 'www.example.com'.strip('cmowz.')
    'example'


    Changed in version 2.2.2: Support for the chars argument.

Ramit


Ramit Prasad | JPMorgan Chase Investment Bank | Currencies Technology
712 Main Street | Houston, TX 77002
work phone: 713 - 216 - 5423

--


> -----Original Message-----
> From: python-list-bounces+ramit.prasad=jpmorgan.com@python.org
> [mailto:python-list-bounces+ramit.prasad=jpmorgan.com@python.org] On Behalf
> Of Rodrick Brown
> Sent: Thursday, March 22, 2012 2:49 PM
> To: python-list@python.org
> Subject: Odd strip behavior
> 
> #!/usr/bin/python
> 
> def main():
> 
> Sent from my iPhone
> --
> http://mail.python.org/mailman/listinfo/python-list
This email is confidential and subject to important disclaimers and
conditions including on offers for the purchase or sale of
securities, accuracy and completeness of information, viruses,
confidentiality, legal privilege, and legal entity disclaimers,
available at http://www.jpmorgan.com/pages/disclosures/email.  

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

RE: Odd strip behavior "Prasad, Ramit" <ramit.prasad@jpmorgan.com> - 2012-03-22 19:54 +0000

csiph-web