小编fun*_*ure的帖子

如何将多个二进制文件复制到Linux系统上的一个文件中?

我需要将包含二进制文件的文件夹的内容复制到另一个目录中的一个二进制文件中.

在Windows中我可以使用:

copy file1 + file2 targetfile /B 
Run Code Online (Sandbox Code Playgroud)

我找不到类似于Linux的东西(我看到了一种方法cat,但我不确定这是否适用于二进制文件).

binary bash copy

49
推荐指数
2
解决办法
6万
查看次数

如何使用Python的doctest-package测试字典相等性?

我正在为输出字典的函数编写doctest.doctest看起来像

>>> my_function()
{'this': 'is', 'a': 'dictionary'}
Run Code Online (Sandbox Code Playgroud)

当我运行它时,它失败了

Expected:
    {'this': 'is', 'a': 'dictionary'}
Got:
    {'a': 'dictionary', 'this': 'is'}
Run Code Online (Sandbox Code Playgroud)

我对这个失败原因的最好猜测是doctest不是检查字典的平等,而是检查__repr__平等.这篇文章表明有一些方法可以欺骗doctest来检查字典的相同性.我怎样才能做到这一点?

python doctest dictionary

37
推荐指数
3
解决办法
5418
查看次数

如何将Sphinx的Autodoc扩展用于私有方法?

我正在使用Sphinx来记录我的python项目.我启用了autodoc扩展,并在我的文档中包含以下内容.

.. autoclass:: ClassName
   :members:
Run Code Online (Sandbox Code Playgroud)

问题是,它只记录了类中的非私有方法.我如何包含私有方法?

python documentation python-sphinx

25
推荐指数
4
解决办法
1万
查看次数

如何使用Python计算文件系统目录的哈希值?

我正在使用此代码计算文件的哈希值:

m = hashlib.md5()
with open("calculator.pdf", 'rb') as fh:
    while True:
        data = fh.read(8192)
        if not data:
            break
        m.update(data)
    hash_value = m.hexdigest()

    print  hash_value
Run Code Online (Sandbox Code Playgroud)

当我在文件夹"文件夹"上尝试时,我得到了

IOError: [Errno 13] Permission denied: folder
Run Code Online (Sandbox Code Playgroud)

我怎么能计算文件夹的哈希值?

python hash

15
推荐指数
4
解决办法
1万
查看次数

如何安装缺少的依赖项(adjustbox.sty)将Ipython笔记本转换为pdf格式?

我有一个IPython笔记本,我试图转换为PDF格式.但是当我去文件并以PDF格式下载时,它会给我以下错误:

nbconvert failed: PDF creating failed
Run Code Online (Sandbox Code Playgroud)

有任何想法吗?我认为一些依赖似乎缺失了.你能建议如何在anaconda中安装它们吗?

编辑:

当我以PDF格式下载时,添加打印到控制台的日志.

[I 16:00:48.396 NotebookApp] Loaded template article.tplx
[I 16:00:49.414 NotebookApp] Writing 51786 bytes to notebook.tex
[I 16:00:49.415 NotebookApp] Building PDF
[I 16:00:49.435 NotebookApp] Running pdflatex 3 times: [u'pdflatex', u'notebook.tex']
[C 16:00:49.853 NotebookApp] pdflatex failed: [u'pdflatex', u'notebook.tex']
    This is pdfTeX, Version 3.14159265-2.6-1.40.15 (TeX Live 2014) (preloaded format=pdflatex)
     restricted \write18 enabled.
    entering extended mode
    (./notebook.tex
    LaTeX2e <2014/05/01>
    Babel <3.9k> and hyphenation patterns for 21 languages loaded.
    (/usr/local/texlive/2014basic/texmf-dist/tex/latex/base/article.cls
    Document Class: article 2007/10/19 v1.4h Standard LaTeX …
Run Code Online (Sandbox Code Playgroud)

latex ipython-notebook

11
推荐指数
1
解决办法
8929
查看次数

如何在Sphinx TOC中包含`genindex`?

Sphinx genindex在构建文档时会生成一个名为的索引,因此禁止在文档中使用该名称。现在,如何在目录中包含指向该索引的链接?

我已经试过了:

.. toctree::
   :maxdepth: 2

   genindex
   api


Indices and tables
==================

* :ref:`genindex`
Run Code Online (Sandbox Code Playgroud)

尽管最后一行确实创建了到文档中该索引的链接,但是在创建目录时,构建不知道引用:

WARNING: toctree contains reference to nonexisting document 'genindex'
Run Code Online (Sandbox Code Playgroud)

python-sphinx

10
推荐指数
1
解决办法
3143
查看次数

如何在承诺回拨中更新Vue应用程序或组件的属性?

我需要更新Firebase回调中的Vue属性,如下所示,但它无法正常工作.这段代码

methods: {
    sign_out : function(e) {
        this.item_count = 0
    }
}
Run Code Online (Sandbox Code Playgroud)

工作,但在承诺回调中设置属性时:

methods: {
  sign_out : function(e) {
  firebase.auth().signOut().then(function() {
      this.item_count = 0
    })
  },
Run Code Online (Sandbox Code Playgroud)

在这种情况下如何设置属性的值?

vue.js vuejs2

10
推荐指数
1
解决办法
5450
查看次数

如何从Sphinx中的Python模块超链接方法?

在使用Sphinx编写文档时,我知道我可以使用Intersphinx链接到一个类:

:py:class:`logging.Logger`
Run Code Online (Sandbox Code Playgroud)

但是我如何直接链接到特定的方法,比如logging.Logger.warning()

python python-sphinx

5
推荐指数
1
解决办法
1336
查看次数

我可以将 pytest 配置为在使用 --looponfail 选项运行时忽略目录吗?

我有一个带有 unittest-module 的目录和一个logs写入调试信息的目录。因为我使用-f/--looponfail选项,所以我需要logs忽略 -directory 中的更改。

tests$ ls
logs  __pycache__  pytest.ini  test_basic.py

tests$ cat pytest.ini
[pytest]
norecursedirs = logs
python_files = test_*.py

tests$ py.test -h
(...)
[pytest] ini-options in the next pytest.ini|tox.ini|setup.cfg file:

  markers (linelist)       markers for test functions
  norecursedirs (args)     directory patterns to avoid for recursion
  usefixtures (args)       list of default fixtures to be used with this project
  python_files (args)      glob-style file patterns for Python test module discovery
  python_classes (args)    prefixes for …
Run Code Online (Sandbox Code Playgroud)

python pytest

5
推荐指数
1
解决办法
4654
查看次数

如何自定义 Cerberus 的错误消息?

我想本地化 Cerberus 返回的错误消息,例如我想实现以下目标:

>>> validator.schema = {'animal': {'forbidden': ['Einhorn']}}
>>> validator({'animal': 'Einhorn'})
False
>>> validator.errors
{'animal': ['VERBOTEN!']}  # instead of 'unallowed value Einhorn'
Run Code Online (Sandbox Code Playgroud)

python cerberus

3
推荐指数
1
解决办法
2967
查看次数

使用 Cerberus 验证两个参数具有相同数量的元素

有没有办法让Cerberus验证两个字段具有相同数量的元素?

例如,该文档将验证:

{'a': [1, 2, 3], b: [4, 5, 6]}
Run Code Online (Sandbox Code Playgroud)

这不会:

{'a': [1, 2, 3], 'b': [7, 8]}
Run Code Online (Sandbox Code Playgroud)

到目前为止,我已经想出了这个模式:

{'a': {'required':False, 'type'= 'list', 'dependencies':'b'},
 'b': {'required':False, 'type'= 'list', 'dependencies':'a'}}
Run Code Online (Sandbox Code Playgroud)

但没有规则可以测试两个字段的长度是否相等。

python cerberus

1
推荐指数
1
解决办法
2132
查看次数