我一直在与可怕的 Gnome API 文档作斗争,并提出了这个扩展:
const St = imports.gi.St;
const Main = imports.ui.main;
const Tweener = imports.ui.tweener;
const GLib = imports.gi.GLib;
let label;
function init() {
label = new St.Bin({ style_class: 'panel-label' });
let stuff = GLib.spawn_command_line_sync("cat /home/user/temp/hello")[1].toString();
let text = new St.Label({ text: stuff });
label.set_child(text);
}
function enable() {
Main.panel._rightBox.insert_child_at_index(label, 0);
}
function disable() {
Main.panel._rightBox.remove_child(label);
}
Run Code Online (Sandbox Code Playgroud)
这应该读取hello文件中的任何内容并将其显示在顶部面板中。但是,如果我更改了hello文件的内容,则必须重新启动 Gnome 才能显示新内容。现在,肯定有一种方法可以动态执行此操作,但我在文档中找不到任何内容。面板中的消息基本上应该始终反映文件中的任何内容。任何想法如何做到这一点?
我正在测试Ansible,我已经陷入了一个相当简单的事情.我配置我/etc/ansible/hosts包含我的服务器的IP:
[web]
1.2.3.4
Run Code Online (Sandbox Code Playgroud)
现在,连接到它ansible all -vvvv -m ping失败,因为我~/.ssh/config的指定服务器使用自定义端口,不在默认位置的密钥文件等.如何告诉Ansible重用我的SSH配置进行连接?
我想不出一个优雅的解决方案。但是,处理HTML文件,对其进行修改并在命令行上使用脚本将其保存回去的最佳方法是什么?我想基本上运行此脚本,证明HTML文件作为参数,data-test=<randomID>在每个<div>元素中添加一个,然后将其保存回该文件中。我当时想我可以编写一个JavaScript脚本来执行,node但不确定如何获取所提供文件的内容,或将内容存储为什么。感谢您的指导。
我有以下应用程序运行调度程序来定期更新全局变量(dict)的状态:
from sanic import Sanic
from sanic.response import text
from apscheduler.schedulers.background import BackgroundScheduler
import bumper
app = Sanic()
scheduler = BackgroundScheduler()
inventory = {1: 1, 2: 2}
@scheduler.scheduled_job('interval', seconds=5)
def bump():
bumper.bump()
@scheduler.scheduled_job('interval', seconds=10)
def manual_bump():
global inventory
inventory[2] += 1
@app.route("/")
async def test(request):
return text(inventory)
if __name__ == "__main__":
scheduler.start()
app.run(host="0.0.0.0", port=8000)
Run Code Online (Sandbox Code Playgroud)
在5秒间隔作业中导入的函数位于同一目录中的不同文件中:
from app import inventory
def bump_inventory():
inventory[1] += 1
print('new', inventory)
Run Code Online (Sandbox Code Playgroud)
然而,这并不像我希望的那样有效.导入的函数更新库存,但更改永远不会传播到原始字典,因此要么bump_inventory处理副本,inventory要么永远不会在函数范围之外更新它.在两个不同的终端:
]$ python app.py
2017-02-19 14:11:45,643: INFO: Goin' Fast @ …Run Code Online (Sandbox Code Playgroud) 我很清楚" closest()运行DOM树直到找到所提供的选择器匹配"的功能.但是,有没有办法让这个函数从定义的点搜索所有元素及其子元素?
<ul id="one" class="level-1">
<li class="item-i">I</li>
<li id="ii" class="item-ii">II
<ul class="level-2">
<li class="item-a">A</li>
<li class="item-b">B
<ul class="level-3">
<li class="item-1">1</li>
<li class="item-2">2</li>
<li class="item-3">3</li>
</ul>
</li>
<li class="item-c">C</li>
</ul>
</li>
<li class="item-iii">III</li>
</ul>
Run Code Online (Sandbox Code Playgroud)
如果我选择一个具有类的元素item-iii并且想要返回具有类的元素item-3,那么选择器会是什么样的?如果我理解closest()正确,它将在DOM树上运行但从不检查是否有任何元素具有与第二个选择器匹配的子元素.
我有一个十行的CSV文件。从这个文件中,我只想要第四行。最快的方法是什么?我正在寻找类似的东西:
with open(file, 'r') as my_file:
reader = csv.reader(my_file)
print reader[3]
Run Code Online (Sandbox Code Playgroud)
reader[3]对于我要实现的语法,哪里显然是不正确的语法。如何将阅读器移至第4行并获取其内容?
鉴于以下字典:
a = {'foo': {'n': 'one', 'text': 'bla'},
'bar': {'n': 'two', 'text': 'blah'},
'baz': {'n': 'three', 'text': 'blabla'}}
Run Code Online (Sandbox Code Playgroud)
我想要一个按以下值排序的结果列表n:
['foo', 'bar', 'baz']
Run Code Online (Sandbox Code Playgroud)
鉴于值n是恒定的并且是已知的(所有这些).所以对于例如起见,只有one,two和three在允许值n.
我假设这必须是sorted()on a.items()的一个组合,一个转换lambda函数替换one为1,依此类推,以便sort函数实际工作.但我似乎无法将它串在一起以使其工作.
python ×3
dictionary ×2
html ×2
javascript ×2
ansible ×1
apscheduler ×1
csv ×1
dom ×1
global ×1
gnome-3 ×1
html-parsing ×1
jquery ×1
list ×1
node.js ×1
sanic ×1
sorting ×1
ssh ×1