我的Matplotlib后端一直在恢复TkAgg.这是一个问题,因为在Windows子系统Linux(WSL)中,你不能做GUI的东西,所以我得到错误
TclError:没有显示名称和没有$ DISPLAY环境变量
我试过添加一个matplotlibrc文件/home/<user>/.config/matplotlib(在Windows文件系统中,这是C:\Users\<user>\AppData\Local\lxss\home\<user>\.config\matplotlib).
我matplotlibrc看起来像这样
backend : Agg
Run Code Online (Sandbox Code Playgroud)
但是,如果我这样做
$ cd /home/<user>/.config/matplotlib
$ ls -A
Run Code Online (Sandbox Code Playgroud)
没有出现.
当我尝试
$ python
>>> import matplotlib
>>> matplotlib.get_backend()
'TkAgg'
Run Code Online (Sandbox Code Playgroud)
很明显,它不是设置后端Agg.为什么不?
更新:
我已经发现只在Windows Python backend : Agg中C:\Users\<user>\AppData\Local\lxss\home\<user>\.config\matplotlib\matplotlibrc更改后端,而将Linux Python作为TkAgg.这很奇怪,因为Windows Python应该只使用C:\Users\<user>\AppData\Local\Enthought\Canopy\User\Lib\site-packages\matplotlib\mpl-data\matplotlibrc,对吧?
我尝试使用 a 是NavigationView因为它看起来非常有用,但我正在努力使其与 MVVM 模式一起工作。
我在这个片段中附加了 MenuItemsSource 属性:
<Page x:Class="App5.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App5"
...>
<Page.DataContext>
<local:MainViewModel></local:MainViewModel>
</Page.DataContext>
<NavigationView MenuItemsSource="{Binding Items}">
<NavigationView.MenuItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</NavigationView.MenuItemTemplate>
</NavigationView>
</Page>
Run Code Online (Sandbox Code Playgroud)
我得到的只是这个:
这很酷,但NavigationViewItem有一个Icon属性来装饰文本。
如何根据绑定到每个的项目设置图标NavigationViewItem?
注意:我真的不想手动添加图标作为 的一部分,MenuItemTemplate因为它不是它应该的方式。我需要的是绑定隐式生成的NavigationViewItems.
问题是如何?
我已经尝试过这个(使用MenuItemContainerStyle),但它不起作用:
<NavigationView MenuItemsSource="{Binding Items}">
<NavigationView.MenuItemContainerStyle>
<Style TargetType="NavigationViewItem">
<Setter Property="Icon" Value="{Binding Converter={StaticResource ItemToIconConverter}}" />
</Style>
</NavigationView.MenuItemContainerStyle>
<NavigationView.MenuItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name}" />
</DataTemplate>
</NavigationView.MenuItemTemplate>
</NavigationView>
Run Code Online (Sandbox Code Playgroud)
注意:使用下面的答案中建议的 XAML(将 aNavigationViewItem …
我正在循环来自Twitter API的JSON响应.每个API响应都给我一条类似于以下内容的推文:
嗨,我的名字是@john,我喜欢#soccer,拜访我
我试图替换@john,并插入<a href=http://twitter.com/john>@john</a>但后面的逗号(,)@john,是问题.
如何在标签之前和之后替换点,逗号等?
Twitter API请求可能会获得带有图像的推文,返回包含类似内容的JSON(删除了非相关位)
["media"]=>
array(1) {
...
[0]=>
array(14) {
...
["media_url"]=>
string(46) "http://pbs.twimg.com/media/XXXXXXXXXXXXXXX.jpg"
...
["type"]=>
string(5) "photo"
["sizes"]=>
array(4) {
["medium"]=>
array(3) {
["w"]=>
int(1200)
["h"]=>
int(1200)
["resize"]=>
string(3) "fit"
}
["large"]=>
array(3) {
["w"]=>
int(2048)
["h"]=>
int(2048)
["resize"]=>
string(3) "fit"
}
...
}
...
}
}
Run Code Online (Sandbox Code Playgroud)
如何访问不同大小的图像版本?我尝试将" http://pbs.twimg.com/media/XXXXXXXXXXXXXXX_medium.jpg "或" http://pbs.twimg.com/media/XXXXXXXXXXXXXXXX_1200x1200.jpg "输入地址栏(显然是真实图像,而不是对于这个例子URL),但没有提出任何东西
假设我有一个基类
from typing import List, Optional
class Node:
def __init__(self, name: str) -> None:
self.name = name
self.children: List['Node'] = []
...
Run Code Online (Sandbox Code Playgroud)
和一个子类
class PropertiesNode(Node):
def __init__(
self, name: str, properties: List[str], inherit: Optional['PropertiesNode']
) -> None:
Node.__init__(self, name)
self.properties = set(properties)
if inherit:
self.properties.update(inherit.properties)
self.children = deepcopy(inherit.children)
for child in self.children:
child.properties.update(properties)
# ^ ERR: "Node" has no attribute "properties" [attr-defined]
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,mypy(正确地)在那里标记了一个错误,因为Node.children明确给出了List[Node].
所以我阅读了泛型类型,在我看来,解决方案是使用TypeVars 和Generic:
from typing import Generic, List, Optional, TypeVar …Run Code Online (Sandbox Code Playgroud) 我有一个字符串,我想- ,( ,) ,& ,$ ,# ,! ,[ ,] ,{ ,} ," ,'从单词的开头或结尾删除任何字符串.如果它之间的话就是忽略那些.
这是一个例子:
var $string = "Hello I am a string, and I am called Jack-Tack!. My -mom is Darlean.";
Run Code Online (Sandbox Code Playgroud)
我想在正则表达式之后上面的文字是这样的:
console.log("Hello I am a string and I am called Jack-Tack My mom is Darlean");
Run Code Online (Sandbox Code Playgroud) python ×2
twitter ×2
.net ×1
api ×1
generics ×1
javascript ×1
jquery ×1
linux ×1
matplotlib ×1
mvvm ×1
mypy ×1
php ×1
regex ×1
type-hinting ×1
uwp ×1