官术网_书友最值得收藏!

Raw strings

Sometimes, particularly when dealing with strings such as Windows filesystem paths or regular expression patterns which use backslashes extensively, the requirement to double-up on backslashes can be ugly and error prone. Python comes to the rescue with its raw strings. Raw strings don't support any escape sequences and are very much what-you-see-is-what-you-get. To create a raw string, precede the opening quote with a lower-case r:

>>> path = r'C:\Users\Merlin\Documents\Spells'
>>>
>>> path
'C:\\Users\\Merlin\\Documents\\Spells'
>>> print(path)
C:\Users\Merlin\Documents\Spells
Although it's common to store and manipulate filesystem paths as strings, for anything but the most straightforward path handling, you should investigate the Python Standard Library pathlib module.
主站蜘蛛池模板: 乌拉特后旗| 漳浦县| 清镇市| 兴国县| 且末县| 杭锦后旗| 平湖市| 九江市| 安宁市| 岳普湖县| 东至县| 咸宁市| 和政县| 大新县| 崇信县| 高碑店市| 岱山县| 泰兴市| 南京市| 长岭县| 乌兰察布市| 嘉荫县| 北安市| 同德县| 株洲县| 南乐县| 庐江县| 明水县| 大理市| 芦山县| 莎车县| 封丘县| 山阴县| 张家口市| 电白县| 交城县| 安义县| 扶风县| 永安市| 拉萨市| 焉耆|