remove the last character or the newline character?



Hello all:

I have the following snippet:

In [1]: fileName = 'Perfect Setup.txt\n'
In [2]: fileName = fileName[0:len(fileName)-1)] # remove the '\n'
character
In [3]: fileName
Out[3]: 'Perfect Setup.txt'

Question one:
Does python provide any function that can remove the last character of
a string?
I don't know whether or not the method I used is efficient

Question two:
Does python provide any function that can remove the newline character
from a string if it exists?



Thank very much!
-Daniel

.



Relevant Pages

  • chapter3
    ... An Informal Introduction to Python ... the hash character, "#", and extend to the end of the physical line. ... string literal is just a hash character. ... Unicode Strings ...
    (Ubuntu)
  • [TOMOYO #16 18/25] TOMOYO: Add utility functions.
    ... * @c: The character to check. ... Pointer to pointer to the string. ... * @filename: The pathname to check. ... * @domainname: The domainname to check. ...
    (Linux-Kernel)
  • Re: UTF-8 / German, Scandinavian letters - is it really this difficult?? Linux & Windows XP
    ... > If I have this in the beginning of my Python script in Linux: ... > in strings and in Tk GUI button labels and GUI window titles and in ... effect on byte string literals. ... DIAERESIS can be encoded in many different character sets, ...
    (comp.lang.python)
  • Re: Problem with sets and Unicode strings
    ... So this is a bug in Python? ... > statement directly compares a unicode string with a byte string. ... If you put character U+00E4 into a unicode string python ... the ASCII codec, because my file is encoded with UTF-8. ...
    (comp.lang.python)
  • Re: Why tuple with one item is no tuple
    ... Complaints about typing an extra character are not all the same. ... >> no way to have both operators in a natural way in python. ... > have mutable keys for dicts that needed copying the very same keys - at ...
    (comp.lang.python)