Delimiter for file paths in Python

Source: Internet
Author: User

The main thing to consider is the delimiter:

The delimiter under Windows system is: \ (backslash)

The delimiter under the Linux system is:/(slash)

When you appear in the character \, you will have to consider the escape character

An escape character is a character like \n,\t,\0, but the character behind \ is no longer the original meaning.

Characters that have special meanings in the string, for example:

In the string, \ n has a special meaning, indicating the meaning of the line break

Of course, in order to deal with this situation, Python offers two workarounds

1. Before the special characters, add \

2. When the characters that need to be escaped are relatively long, the previous approach is obviously not efficient, and there is another way

The entire string preceded by the letter R

We can look at:

(where the first path is the one I built myself) python or the more tedious way to do this: in each \ before adding \

Of course, in Linux there is no need to consider this situation,/There is no escape character in the case

Fortunately, Python supports both types of writing, so it depends on your personal preferences when filling in the file path.

Delimiter for file paths in Python

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.