小编Ark*_*een的帖子

Mutagen:如何提取专辑封面属性?

我正在尝试使用 python 3.7.1 和 mutagen 1.42 从 mp3 文件中获取专辑封面图片的属性(到目前为止只是宽度和高度,但可能更多),但到目前为止似乎没有任何效果。我还能够正确提取一些其他信息

该文档讲述了APIC,但尝试显示所有标签并没有显示与任何图片相关的任何内容(并且我的 mp3 测试文件确实有专辑图片):

import os,sys
from mutagen.mp3 import MP3
from mutagen.easyid3 import EasyID3

song_path = os.path.join(sys.argv[1]) # With sys.argv[1] the path to a mp3 file containing a picture
track = MP3(song_path, ID3=EasyID3)
pprint(track.get('title')[0] + ' ' + str(track.info.length) + 's, ' + str(int(track.info.bitrate / 1000)) + 'kbps')
print(track.keys())
Run Code Online (Sandbox Code Playgroud)

结果,使用我的文件:

> Exponential Tears 208.0s, 205kbps
> ['album', 'copyright', 'encodedby', 'length', 'title', 'artist', 'albumartist', 'tracknumber', 'genre', 'date', 'originaldate']
Run Code Online (Sandbox Code Playgroud)

(这个 …

python id3 image mutagen

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

Networkx:在 DAG 中获取所有可能的路径

我试图将有向(无环)图拆分为方向连接的路径,依赖于连接性

示例图

当我测试弱连接和强连接子图时,我得到的是:

Weak connectivity :
['16', '17'], ['3', '41', '39', '42']
Strong connectivity :
['17'], ['16'], ['39'], ['41'], ['3'], ['42']
Run Code Online (Sandbox Code Playgroud)

我理解弱连接结果,但不是强连接结果,因为我期望 3 个子图:[16, 17]、[42, 39] 和 [3, 41, 39]。

我在这里错过了什么,为什么那些单节点列表?如何得到预期的结果?

这是代码:

import networkx as nx
import matplotlib.pyplot as plt

G = nx.DiGraph()
G.add_edges_from([('16', '17'), ('3', '41'), ('41', '39'), ('42', '39')])

print("Weak connectivity : ")
for subgraph in (G.subgraph(c).copy() for c in nx.weakly_connected_components(G)) :
    print(subgraph.nodes)
print("Strong connectivity : ")
for subgraph in (G.subgraph(c).copy() for c in nx.strongly_connected_components(G)) :
    print(subgraph.nodes) …
Run Code Online (Sandbox Code Playgroud)

python graph directed-graph networkx

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

Python正则表达式:计算和替换数值

我有一个正则表达式问题,它似乎不像我想的那么普遍:我想提取所有具有px单位的数值,应用一些计算,然后将新值重新注入我的字符串中。我不想包含px字符串(请参见下面的示例),但是我可以使用保留它们的另一种方法,或者更改单位类型。

例如,将值乘以2.5:

"2px aperture 12px science 2.1px yummy cake"

我想要 "5 aperture 30 science 5.25 yummy cake"

我做了一个粗略的脚本,但是我没有得到想要的输出:

import re
my_string = "2px aperture 12px science 2.1px yummy cake"
nb_list= re.findall(r"([0-9.]+)px", my_string)
splitted_string = re.findall('.*?px', my_string)
print(f"splitted_string = {splitted_string}")
print(f"nb_list = {nb_list}")
new_list = []
for i in range(0, len(nb_list)):
  new_n = str(float(nb_list[i])*2.5)
  new_string = re.sub(r"[0-9.]+px", new_n, splitted_string[i])
  new_list.append(new_string)
new_list = ''.join(new_list)
print(f"new_list = {new_list}")
Run Code Online (Sandbox Code Playgroud)

结果:

new_list = 5.0 aperture 30.0 science 5.25
Run Code Online (Sandbox Code Playgroud)

我知道为什么会得到这个结果,但是我不知道要进行什么更改才能获得所需的输出。

python regex string numeric

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

cytoscape.js 图的条件样式

我想根据全局 Javascript 变量更改图形的样式。例如,假设我的边得到了nameprice属性,我想根据全局label_type变量使边的标签不同:

let lable_type = 'I_want_name_labels'
switch(lable_type) {
  case 'I_want_name_labels':
    cy.style().selector('edge').style({'label': 'data(name)'});
    break;
  case 'I_want_price_labels':
    cy.style().selector('edge').style({'label': 'data(price)'});
    break;
}
Run Code Online (Sandbox Code Playgroud)

上面的代码根本没有做任何事情(没有显示标签),我真的不明白为什么。我的边缘具有以下结构:

{
  "data": {
    "id": "node_node2",
    "source": "node1",
    "target": "node2",
    "directed": true,
    "name": "Baltazar",
    "price": 1095.73
  }
}
Run Code Online (Sandbox Code Playgroud)

注意:我尝试使用cy.filter('edge').style({'label': 'data(name)'}),但data似乎无法通过这种方式访问​​,我收到了以下警告:

The style property `label: data(name)` is invalid
Run Code Online (Sandbox Code Playgroud)

那么,如何使用 cytoscape.js 获得条件样式?我在这里错过了什么?

javascript styles graph conditional-statements cytoscape.js

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