文档章节

Why can't raw strings end with a backslash

姐夫
 姐夫
发布于 2012/08/31 18:06
字数 182
阅读 33
收藏 0

More precisely, they can't end with an odd number of backslashes: the unpaired backslash at the end escapes the closing quote character, leaving an unterminated string.

Raw strings were designed to ease creating input for processors (chiefly regular expression engines) that want to do their own backslash escape processing. Such processors consider an unmatched trailing backslash to be an error anyway, so raw strings disallow that. In return, they allow you to pass on the string quote character by escaping it with a backslash. These rules work well when r-strings are used for their intended purpose.

If you’re trying to build Windows pathnames, note that all Windows system calls accept forward slashes too:

f = open("/mydir/file.txt")  # works fine!


If you’re trying to build a pathname for a DOS command, try e.g. one of
dir = r"\this\is\my\dos\dir" "\\"
dir = r"\this\is\my\dos\dir\ "[:-1]
dir = "\\this\\is\\my\\dos\\dir\\"

 

 

今天在python-cn 看到的讨论,先记下来,以后整理

本文转载自:http://docs.python.org/py3k/faq/design.html#why-can-t-raw-strings-r-strings-end-with-a-backslash

姐夫
粉丝 49
博文 34
码字总数 8509
作品 0
浦东
程序员
私信 提问
nsq使用的TOML配置文件规范文档中文版

在阅读 nsq 源码的时候,发现nsq使用 TOML 配置文件规范。顺带翻译了大部分。采用英中文混排的方式,这样比较容易理解。 toml-lang/toml TOML Tom's Obvious, Minimal Language. 直观的,最小...

智深
2014/07/31
613
2
Python 3.6文档阅读笔记

2017.4.21 argument A value passed to a function (or method) when calling the function. There are two kinds of argument: Arguments are assigned to the named local variables in a ......

月moon
2017/04/22
0
0
JDBC Statement设置逃逸字符

JDBC Statement的逃逸字符开关设置 void setEscapeProcessing(boolean enable) throws SQLException Sets escape processing on or off. If escape scanning is on (the default), the drive......

月下独酌100
2012/06/23
416
0
struts 1.2+ 使用 通配符映射 进行 action 的分发

Using Wildcards in ActionMappings [Since Apache Struts 1.2.0] As an application grows in size, so will the number of action mappings. Wildcards can be used to combine similar ma......

SeanCai
2010/08/31
519
0
Postgresql - Pattern Matching

There are three separate approaches to pattern matching provided by PostgreSQL: the traditional SQL LIKE operator, the more recent SIMILAR TO operator (added in SQL:1999), and P......

张悟空
2014/09/01
88
0

没有更多内容

加载失败,请刷新页面

加载更多

3_数组

3_数组

行者终成事
今天
7
0
经典系统设计面试题解析:如何设计TinyURL(二)

原文链接:https://www.educative.io/courses/grokking-the-system-design-interview/m2ygV4E81AR 编者注:本文以一道经典的系统设计面试题:《如何设计TinyURL》的参考答案和解析为例,帮助...

APEMESH
今天
7
0
使用logstash同步MySQL数据到ES

概述   在生成业务常有将MySQL数据同步到ES的需求,如果需要很高的定制化,往往需要开发同步程序用于处理数据。但没有特殊业务需求,官方提供的logstash就很有优势了。   在使用logstas...

zxiaofan666
今天
10
0
X-MSG-IM-分布式信令跟踪能力

经过一周多的鏖战, X-MSG-IM的分布式信令跟踪能力已基本具备, 特点是: 实时. 只有要RX/TX就会实时产生信令跟踪事件, 先入kafka, 再入influxdb待查. 同时提供实时sub/pub接口. 完备. 可以完整...

dev5
今天
7
0
OpenJDK之CyclicBarrier

OpenJDK8,本人看的是openJDK。以前就看过,只是经常忘记,所以记录下 图1 CyclicBarrier是Doug Lea在JDK1.5中引入的,作用就不详细描述了,主要有如下俩个方法使用: await()方法,如果当前线...

克虏伯
今天
8
0

没有更多内容

加载失败,请刷新页面

加载更多

返回顶部
顶部