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

Peng Yu pengyu.ut at gmail.com
Sat Feb 24 14:16:02 EST 2018


On Sat, Feb 24, 2018 at 1:08 PM, Peng Yu <pengyu.ut at gmail.com> wrote:
> 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?

Also, this is not printed as \f or \e. I'd like things like \a, \b,
... \v be printed as such. Is there a way to do so in python?

>>> print repr('\f')
'\x0c'
>>> print repr('\e')
'\\e'

-- 
Regards,
Peng



More information about the Python-list mailing list