How to only get \n for newline without the single quotes?

Peng Yu pengyu.ut at gmail.com
Sat Feb 24 14:08:34 EST 2018


On Sat, Feb 24, 2018 at 12:45 PM, Wildman via Python-list
<python-list at python.org> wrote:
> On Sat, 24 Feb 2018 11:41:32 -0600, Peng Yu wrote:
>
>> I would like to just get the escaped string without the single quotes.
>> Is there a way to do so? Thanks.
>>
>>>>> x='\n'
>>>>> print repr(x)
>> '\n'
>
> Python 3.5.3 (default, Jan 19 2017, 14:11:04)
> [GCC 6.3.0 20170118] on linux
> Type "help", "copyright", "credits" or "license" for more information.
>>>> x='/n'
>>>> print(repr(x))
> '/n'
>>>> print(repr(x).strip("'"))
> /n
>>>>
>
> Python 2.7.13 (default, Nov 24 2017, 17:33:09)
> [GCC 6.3.0 20170516] on linux2
> Type "help", "copyright", "credits" or "license" for more information.
>>>> x='/n'
>>>> print repr(x)
> '/n'
>>>> print repr(x).strip("'")
> /n
>>>>

I was looking for something builtin python. There is not such a builtin way?

-- 
Regards,
Peng



More information about the Python-list mailing list