小编hyp*_*ics的帖子

修改Sphinx主题"阅读文档"的内容宽度

我正在使用"阅读文档"Sphinx主题作为我的文档.在原始主题中,给出如下

http://read-the-docs.readthedocs.org/en/latest/theme.html

内容或主要布局宽度设计为移动友好.但是,对于我的项目,我希望这会更广泛.我不知道HTML,因此如果任何人可以给我一些线索来增加内容(布局)宽度,我将不胜感激.

html themes width python-sphinx

32
推荐指数
8
解决办法
2万
查看次数

使用Python解析多行JSON文件的问题

我试图json在Python 2.7中使用库解析JSON多行文件.简化的示例文件如下:

{
"observations": {
    "notice": [
        {
            "copyright": "Copyright Commonwealth of Australia 2015, Bureau of Meteorology. For more information see: http://www.bom.gov.au/other/copyright.shtml http://www.bom.gov.au/other/disclaimer.shtml",
            "copyright_url": "http://www.bom.gov.au/other/copyright.shtml",
            "disclaimer_url": "http://www.bom.gov.au/other/disclaimer.shtml",
            "feedback_url": "http://www.bom.gov.au/other/feedback"
        }
    ]
}
}
Run Code Online (Sandbox Code Playgroud)

我的代码如下:

import json

with open('test.json', 'r') as jsonFile:
    for jf in jsonFile:
        jf = jf.replace('\n', '')
        jf = jf.strip()
        weatherData = json.loads(jf)
        print weatherData
Run Code Online (Sandbox Code Playgroud)

不过,我收到如下错误:

Traceback (most recent call last):
File "test.py", line 8, in <module>
weatherData = json.loads(jf)
File "/home/usr/anaconda2/lib/python2.7/json/__init__.py", line 339, in loads …
Run Code Online (Sandbox Code Playgroud)

python parsing json multiline

5
推荐指数
2
解决办法
7890
查看次数

使用自定义 Python 脚本在 Ansible Tower 中自定义凭据

我正在尝试在 Ansible Tower 中实现自定义脚本来动态导入库存。自定义脚本基本上是使用 Python 编写的,并与充当域控制器 (DC) 的 Windows 2012 Server 进行交互。当从 Ansible Tower 执行脚本时,它会从 DC 中提取所有工作站并添加到 Ansible 清单中。为此,我必须在 Python 脚本中以纯文本形式传递 DC 的登录凭据,这是不希望的。因此,我们正在寻找是否有一种方法可以在 Ansible Tower 中存储凭证并将其作为 Python 脚本中的变量传递。

在研究这个主题时,基本上发现了Custom Credential in a Custom Inventory Script,它在 Ansible Tower 中的定义如下:

在 Ansible tower 中的自定义凭据下,输入配置:

{
"fields": [{
    "id": "username",
    "label": "<Username>",
    "type": "string",
}, {
    "id": "password",
    "label": "<Password>",
    "type": "string",
    "secret": true
}],
}
Run Code Online (Sandbox Code Playgroud)

然后,喷油器配置:

{
"env": {
    "SAT_USERNAME": "{{username}}",
    "SAT_PASSWORD": "{{password}}"
}
}
Run Code Online (Sandbox Code Playgroud)

将上述内容保存在 Ansible Tower 中后,据我了解,SAT_USERNAME …

python ansible ansible-tower ansible-inventory

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

使用 Python 从文本文件中跳过行

我正在处理一个非常大的日志文件以使用 Python 正则表达式提取信息。但是,我只想在找到特定字符串(在本例中为Starting time loop. 日志文件的最小版本如下:

Pstream initialized with:
floatTransfer      : 0
nProcsSimpleSum    : 0
commsType          : nonBlocking
polling iterations : 0
sigFpe : Enabling floating point exception trapping (FOAM_SIGFPE).
fileModificationChecking : Monitoring run-time modified files using timeStampMaster
allowSystemOperations : Disallowing user-supplied system call operations

// * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * …
Run Code Online (Sandbox Code Playgroud)

python regex

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