Python-raw string Suppression Escape

Source: Internet
Author: User

Tag: The raw input is the BSP window txt span string that will

Raw string Suppression escape

There are times when we need to open files and so on, then we need to enter the path, especially the window path, mostly using backslashes, this time there will be problems

For example:

handler=open(‘c:\nb123.txt‘,‘w‘)  

This time there is a problem, it is open nb123 this text file, but because there is a backslash in front, in the escape is a newline, causing ambiguity

So, we need to change the path to look like this:

Handler=open (<spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string">r'C:\nb123.txt'</span></span></span></span></span>,<spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string">'W'</span></span></span></span></span>) Handler=open (<spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string">'C:\\nb123.txt'</span></span></span></span></span>,<spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string"><spanclass="hljs-string">'W'</span></span></span></span></span>)

This time is legal, use R to suppress escape, or use double backslashes

Python-raw string Suppression escape

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.