我正在使用python 2.7,我想解析我已经从文本文件中提取的字符串HTTP响应字段.什么是最简单的方法?我可以使用BaseHTTPServer解析请求,但无法找到响应的内容.
我的回答非常标准,并采用以下格式
HTTP/1.1 200 OK
Date: Thu, Jul 3 15:27:54 2014
Content-Type: text/xml; charset="utf-8"
Connection: close
Content-Length: 626
Run Code Online (Sandbox Code Playgroud)
提前致谢,
原始.gitmodules文件使用硬编码的httpsURL但是对于一些自动化测试,我克隆ssh并使子模块URL相对,如../ModuleName.我也不想将这些变化推回到回购中.
# change the https://github.com/ with git@github.com:
sed -i 's/https:\/\/github.com\//git@github.com:/g' ".git/config"
# delete the url lines from the submodule blocks of .git/config
sed -i '/submodule/ {$!N;d;}' ".git/config"
# change hardcoded https:// urls of submodules to relative ones
sed -i 's/https:\/\/github.com\/ProjName/../g' ".gitmodules"
# also make the same change in the .git/modules/*/config
sed -i 's/https:\/\/github.com\/ProjName/../g' .git/modules/*/config
# sync and update
git submodule sync
git submodule update --init --recursive --remote
Run Code Online (Sandbox Code Playgroud)
通过上面的代码片段,它可以实现我想要的功能.然而,令人讨厌的是,.git/modules/文件夹似乎没有版本控制,但如果我只是删除它,git submodule …
当我编译正则表达式并将其分配给变量或将其添加到列表时,我怀疑在 Python 2.x 和 3.x 上得到不同的行为。
import re
z = re.compile('a')
print(z)
Run Code Online (Sandbox Code Playgroud)
上面的代码片段打印在 2.x 上
<_sre.SRE_Pattern object at 0x7ff839e57030>
Run Code Online (Sandbox Code Playgroud)
在 3.x 上
re.compile('a')
Run Code Online (Sandbox Code Playgroud)
第一个看起来像正则表达式被编译并准备好在我需要它时使用(这是我想要的),但第二个仍然说re.compile.
这是否意味着正则表达式会在我需要时即时编译,更糟糕的是每次引用z并执行类似操作时都会重新编译z.match('a')?或者,所描述的 Python 3 行为只是装饰性的,并且还在引擎盖下维护了一个编译副本?
我的观点是,我(静态地)在源文件的开头编译我的正则表达式,因此可以节省一些时间,以便我在循环中重复引用它们,但如果没有发生这种情况,那就不好了。