所以我在twitter上看到了这两个 问题.如何1.real
语法错误但1 .real
不是?
>>> 1.real
File "<stdin>", line 1
1.real
^
SyntaxError: invalid syntax
>>> 1 .real
1
>>> 1. real
File "<stdin>", line 1
1. real
^
SyntaxError: invalid syntax
>>> 1 . real
1
>>> 1..real
1.0
>>> 1 ..real
File "<stdin>", line 1
1 ..real
^
SyntaxError: invalid syntax
>>> 1.. real
1.0
>>> 1 .. real
File "<stdin>", line 1
1 .. real
^
SyntaxError: invalid syntax
Run Code Online (Sandbox Code Playgroud) 我正在设置一个Juypter服务器来托管我的笔记本电脑.
在 /home/user/.jupyter/notebook_configuration.py
c.NotebookApp.certfile = u'/home/user/.jupyter/mycert.pem'
c.NotebookApp.keyfile = u'/home/user/.jupyter/mykey.key'
Run Code Online (Sandbox Code Playgroud)
如果我在控制台上跑
jupyter notebook --ip="ip_address" --port=8000 --certfile=mycert.pem --keyfile mykey.key
Run Code Online (Sandbox Code Playgroud)
服务器和证书工作!
但是,当我设置DNS条目并尝试路由到服务器时,我遇到了这个错误
SSL Error on 10 ('ip_address', 63748): [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:600)
Run Code Online (Sandbox Code Playgroud)
这是怎么回事?
我有两个 Cloudwatch 见解查询,我希望能够并行运行并比较两者的结果。
stats count(*) as requestIdCount by @requestId
| filter @message like /START RequestId/
| filter requestIdCount > 1
Run Code Online (Sandbox Code Playgroud)
stats count(*) as requestIdCount by @requestId
| filter @message like /END RequestId/
| filter requestIdCount > 1
Run Code Online (Sandbox Code Playgroud)
能够做到这一点会很棒
fields (
stats count(*) as requestIdCount by @requestId
| filter @message like /END RequestId/
| filter requestIdCount > 1) as EndRequestCount,
(
stats count(*) as requestIdCount by @requestId
| filter @message like /START RequestId/
| filter requestIdCount > 1) as StartRequestCount
Run Code Online (Sandbox Code Playgroud)
但是我现在看不到任何方法可以在见解中进行子查询。有没有一种方法可以组合这样的查询?
这篇Stack Overflow帖子是关于使一个对象成为Python中的迭代器.
在Python 2中,这意味着您需要实现一个__iter__()
方法和一个next()
方法.但是在Python 3中,您需要实现一个不同的方法,而不是next()
您需要实现的方法__next__()
.
如何在Python 2和3中创建一个迭代器对象?
如果我编译一个正则表达式
>>> type(re.compile(""))
<class '_sre.SRE_Pattern'>
Run Code Online (Sandbox Code Playgroud)
并希望将该正则表达式传递给函数并使用Mypy来键入check
def my_func(compiled_regex: _sre.SRE_Pattern):
Run Code Online (Sandbox Code Playgroud)
我遇到了这个问题
>>> import _sre
>>> from _sre import SRE_Pattern
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: cannot import name 'SRE_Pattern'
Run Code Online (Sandbox Code Playgroud)
您似乎可以导入_sre
但由于某种原因SRE_Pattern
不可导入.
我有在 Ubuntu 14.04 上运行的 apache2 Web 服务器。默认情况下,当我启动 apache Web 服务器时,http://localhost
我可以看到从 /var/www/html/index.html 文件启动的“Apache2 Ubuntu 默认页面”。
我在 /home/ubuntu/myprojects/ 位置有一个烧瓶应用程序。Flask 应用程序在 virtualenv 上运行,并具有适当的文件夹结构来呈现 html 文件。下面是文件夹结构
/home/ubuntu/myprojects/hello/hello.py(flask 应用程序渲染 html)/home/ubuntu/myprojects/hello/templates/hello.html
Flask 应用程序代码如下:
from flask import Flask
from flask import render_template
from flask import request
app = Flask(__name__)
@app.route('/')
def my_form():
return render_template("hello.html")
if __name__ == '__main__':
app.debug = True
app.run(host='0.0.0.0')
Run Code Online (Sandbox Code Playgroud)
当我运行http://localhost:5000
hello.html 时呈现。我想在http://localhost
没有指定任何端口号的情况下调用hello.py flask 应用程序时呈现 hello.html 。为此,我添加了以下代码:
app.run(host='0.0.0.0', port=80)
Run Code Online (Sandbox Code Playgroud)
但是,当我运行 Flask 应用程序时,存在错误:
* Running on http://0.0.0.0:80/ (Press CTRL+C to quit) …
Run Code Online (Sandbox Code Playgroud) 我在模拟函数时遇到了一些麻烦。所述函数被导入并用于run_parsers.py
,我得到
ImportError: 'No module named run_parsers'
Run Code Online (Sandbox Code Playgroud)
当我尝试mock.patch
run_parsers.py
.
这是我的测试代码 test_run_parsers.py
from .. import run_parsers # Used in all my other tests.
def test_node_data_parser_throws_exception(self):
def parser():
return NotImplementedError()
with mock.patch("run_parsers.get_node_paths") as node_paths:
node_paths.return_value = "node_1"
run_parsers.get_node_data(parser, "/a/path")
Run Code Online (Sandbox Code Playgroud)
这是我的存储库结构
control_scripts
??? __init__.py
??? README.md
??? run_all_parsers.py
??? run_parsers.py
??? tests
??? __init__.py
??? test_run_parsers.py
Run Code Online (Sandbox Code Playgroud)
根据本教程,我应该模拟导入函数的位置。这就是为什么我试图模拟调用模块而不是定义 get_node_paths 的模块
我收到了错误,
AttributeError: 'Request' object has no attribute 'add_data'
来自使用urllib.request的库
在Python 2.7-3.3中,urllib.request包含一个add_data()
方法.
但在Python 3.4中,文档指出,
如何在Python3.4中向urllib请求添加数据?
为什么在我的代码库的不同部分将相同的字符编码为不同的字节?
我有一个单元测试,它生成一个临时文件树,然后检查以确保我的扫描确实找到了有问题的文件。
def test_unicode_file_name():
test_regex = "é"
file_tree = {"files": ["é"]} # File created with python.open()
with TempTree(file_tree) as tmp_tree:
import pdb; pdb.set_trace()
result = tasks.find_files(test_regex, root_path=tmp_tree.root_path)
expected = [os.path.join(tmp_tree.root_path, "é")]
assert result == expected
Run Code Online (Sandbox Code Playgroud)
for dir_entry in scandir(current_path):
if dir_entry.is_dir():
dirs_to_search.append(dir_entry.path)
if dir_entry.is_file():
testing = dir_entry.name
if filename_regex.match(testing):
results.append(dir_entry.path)
Run Code Online (Sandbox Code Playgroud)
当我开始深入研究时,我发现测试字符(从我的单元测试中复制)和dir_entry.name
编码为不同字节的字符。
(Pdb) testing
'é'
(Pdb) 'é'
'é'
(Pdb) testing == 'é'
False
(Pdb) testing in 'é'
False
(Pdb) type(testing)
<class 'str'>
(Pdb) type('é') …
Run Code Online (Sandbox Code Playgroud) python ×8
python-3.x ×2
apache ×1
flask ×1
iterator ×1
jupyter ×1
mocking ×1
mypy ×1
python-2.7 ×1
python-3.4 ×1
ssl ×1
ubuntu-14.04 ×1
unicode ×1
unit-testing ×1
urllib ×1
uuid ×1