请注意,这类似于如何在 asdict 中获取 @property 方法?。
我有一个(冻结的)嵌套数据结构,如下所示。定义了一些(纯粹)依赖于字段的属性。
import copy
import dataclasses
import json
from dataclasses import dataclass
@dataclass(frozen=True)
class Bar:
x: int
y: int
@property
def z(self):
return self.x + self.y
@dataclass(frozen=True)
class Foo:
a: int
b: Bar
@property
def c(self):
return self.a + self.b.x - self.b.y
Run Code Online (Sandbox Code Playgroud)
我可以按如下方式序列化数据结构:
class CustomEncoder(json.JSONEncoder):
def default(self, o):
if dataclasses and dataclasses.is_dataclass(o):
return dataclasses.asdict(o)
return json.JSONEncoder.default(self, o)
foo = Foo(1, Bar(2,3))
print(json.dumps(foo, cls=CustomEncoder))
# Outputs {"a": 1, "b": {"x": 2, "y": 3}}
Run Code Online (Sandbox Code Playgroud)
但是,我还想序列化属性 ( …
python serialization immutability python-3.x python-dataclasses
来自https://github.com/google/deepdream/blob/master/dream.ipynb
def objective_L2(dst): # Our training objective. Google has since release a way to load
dst.diff[:] = dst.data # arbitrary objectives from other images. We'll go into this later.
def make_step(net, step_size=1.5, end='inception_4c/output',
jitter=32, clip=True, objective=objective_L2):
'''Basic gradient ascent step.'''
src = net.blobs['data'] # input image is stored in Net's 'data' blob
dst = net.blobs[end]
ox, oy = np.random.randint(-jitter, jitter+1, 2)
src.data[0] = np.roll(np.roll(src.data[0], ox, -1), oy, -2) # apply jitter shift
net.forward(end=end)
objective(dst) # specify the optimization objective …Run Code Online (Sandbox Code Playgroud) 我目前正在尝试创建一组切换按钮,这些按钮类似于Eclipse的格式化程序首选项中使用的按钮:

目前我已通过以下方式尝试此操作:
public class Exercise extends JFrame {
private String[] buttonNames = {"A", "B", "C", "D", "E"};
Exercise() {
final JPanel topPanel = new JPanel();
topPanel.setLayout(new GridBagLayout());
GridBagConstraints c = new GridBagConstraints();
int tabCount = 0;
final ButtonGroup topButtonGroup = new ButtonGroup();
for (String buttonName : buttonNames) {
JToggleButton tabButton = new JToggleButton(buttonName);
topButtonGroup.add(tabButton);
c.fill = GridBagConstraints.HORIZONTAL;
c.insets = new Insets(0, -6, 0, -7); // Questionable line
c.gridx = tabCount;
c.gridy = 0;
topPanel.add(tabButton, c);
tabCount++;
}
this.add(topPanel);
this.setVisible(true);
this.pack(); …Run Code Online (Sandbox Code Playgroud) 目前,我正在将Swing应用程序的首选项面板迁移到JavaFX.应用程序首先读取需要从xml文件构建的内容.然后,应用程序使用该信息创建并将大量JComponents和关联的JLabel附加到面板以及一些分隔符,如下所示:
layout = new FormLayout(description, "");
builder = new DefaultFormBuilder(bottomLayout);
// In some loop
propertyControlImpl.layout(builder);
public void layout(final DefaultFormBuilder builder) {
final JLabel label = builder.append(TextUtils.getOptionalText(getLabel()), component);
// set the text property of label, etc
}
public void layout(final DefaultFormBuilder builder) {
builder.appendSeparator(TextUtils.getOptionalText(getLabel()));
}
Run Code Online (Sandbox Code Playgroud)
将此转换为JavaFX的最佳方法是什么?是否有为此制作的开源JavaFX库?如果没有,我计划使用堆叠的TitlePanes和hbox 的组合来放置各种控件(组件).
这是我想要生成的模拟(使用JavaFX SceneBuilder创建).我尚未完美地对齐所有内容,但我希望所有标签都正确对齐并占据最长标签的空间.所有要在标签右侧左对齐的组件(就像DefaultFormBuilder如何布置一样):

我有一个简单的docker-compose设置如下.
version: "3"
services:
main:
image: python:3.5.2
entrypoint: /usr/bin/yes
network_mode: bridge
another:
image: python:3.5.2
entrypoint: /usr/bin/yes
network_mode: bridge
Run Code Online (Sandbox Code Playgroud)
如果我运行并尝试ping另一个容器,我得到以下输出.
$ docker-compose up -d
Recreating dockerplayground_main_1 ...
Recreating dockerplayground_another_1 ... done
$ docker-compose ps
Name Command State Ports
---------------------------------------------------------
dockerplayground_another_1 /usr/bin/yes Up
dockerplayground_main_1 /usr/bin/yes Up
$ docker ps
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
3b256d98bf2c python:3.5.2 "/usr/bin/yes" 7 seconds ago Up 6 seconds dockerplayground_another_1
dfc04a452547 python:3.5.2 "/usr/bin/yes" 7 seconds ago Up 6 seconds dockerplayground_main_1
$ docker exec -it 3b256d98bf2c …Run Code Online (Sandbox Code Playgroud) 这是我之前的问题的延续,但它解决了一个对其他人有用的特定问题,所以我想我会把它作为一个单独的问题发布.
我已经成功创建了一个JTabbedPane,但是有一个蓝色边框突出显示,显示我要删除的选项卡:

为了澄清我的意思,这里是一张JTabbedPane的图片,没有Eclipse的蓝色边框高亮:

我试过的东西已经被注释掉了:
public class SeaGlassExercise {
public static void initWindow() {
JFrame frame = new JFrame("Application Name");
CustomTabbedPane content = new CustomTabbedPane();
frame.setContentPane(content);
frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
frame.setLocationByPlatform(true);
// try {
// UIManager.setLookAndFeel(
// UIManager.getSystemLookAndFeelClassName());
// } catch (Exception e) {
// e.printStackTrace();
// }
// SwingUtilities.updateComponentTreeUI(frame);
frame.pack();
frame.setVisible(true);
}
public static void main(String[] args) {
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
initWindow();
}
});
}
}
class CustomTabbedPane extends JPanel {
public CustomTabbedPane() {
super(new GridLayout(1, …Run Code Online (Sandbox Code Playgroud) 在以下命令中,我收到以下错误
$ meteor test-packages --driver-package practicalmeteor:mocha rocketchat:spotify
Run Code Online (Sandbox Code Playgroud)
控制台输出
=> Errors prevented startup:
While building package local-test:rocketchat:spotify:
error: No plugin known to handle file 'spotify.test.coffee'. If you want this file to be a static asset, use
addAssets instead of addFiles; eg, api.addAssets('spotify.test.coffee', 'client').
Run Code Online (Sandbox Code Playgroud)
我很困惑,因为我在Package.onUse下指定了coffeescript包.
rocketchat-Spotify的/ package.js
Package.describe({
name: 'rocketchat:spotify',
version: '0.0.1',
summary: 'Message pre-processor that will translate spotify on messages',
git: ''
});
Package.onUse(function(api) {
api.versionsFrom('1.0');
api.use([
'coffeescript', # Coffeescript is included here?
'templating',
'underscore',
'rocketchat:oembed@0.0.1',
'rocketchat:lib'
]);
api.addFiles('lib/client/widget.coffee', 'client');
api.addFiles('lib/client/oembedSpotifyWidget.html', …Run Code Online (Sandbox Code Playgroud) 我知道一个简单的解决方案就是手动将 Rails 引擎的 /public 文件夹中的所有文件复制到 Rails 应用程序的 /public 文件夹中。但是,这意味着每次安装都需要手动复制。
此外,因为我的引擎使用的 Javascript 文件具有硬编码的图像路径,所以我不能简单地将所有静态文件放在 app/assets 或供应商/assets 下,因为随后 Rails 会将它们复制到 public/assets 下。我无法更改 Sprockets 输出文件的路径,因为我有其他 gem 期望其资产位于默认的 public/assets 文件夹中。
我尝试做类似的事情
class Engine < ::Rails::Engine
if Rails.application.config.serve_static_assets
initializer "static assets" do |app|
app.middleware.insert_before(::ActionDispatch::Static, ::ActionDispatch::Static, "#{root}/public")
end
end
end
Run Code Online (Sandbox Code Playgroud)
但这仅适用于发展。
我正在遵循sbt官方安装说明。
$ sudo apt-key adv --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
Executing: /tmp/apt-key-gpghome.uRI0yiusG0/gpg.1.sh --keyserver hkp://keyserver.ubuntu.com:80 --recv 2EE0EA64E40A89B84B2DF73499E82A75642AC823
gpg: keyserver receive failed: Invalid argument
Run Code Online (Sandbox Code Playgroud)
编辑:
我试过挖掘执行的gpg.1.sh脚本。这是对gpg的最终调用。
$ sudo cat /tmp/apt-key-gpghome.IRnmlx6hfX/gpg.0.sh
#!/bin/sh
exec 'gpg' --ignore-time-conflict --no-options --no-default-keyring \
--homedir '/tmp/apt-key-gpghome.IRnmlx6hfX' --no-auto-check-trustdb --trust-model always "$@"
Run Code Online (Sandbox Code Playgroud)
编辑2:
我试图直接从密钥服务器中查询密钥,但是没有运气。参见http://keyserver.ubuntu.com/pks/lookup?search=2EE0EA64E40A89B84B2DF73499E82A75642AC823&op=vindex。钥匙可能丢失了吗?
编辑3:
我在2月24日再次尝试,现在可以使用了!
例如,给定
def expensive_call(x):
print(x)
if x == "d":
return x
def expensive_call_2(x, y):
print(x)
print(y)
return x + y
a = [expensive_call("a"), expensive_call_2("b", "c"), expensive_call("d")]
next((e for e in a if e is not None), 'All are Nones')
Run Code Online (Sandbox Code Playgroud)
输出是
a
b
c
d
Out[22]: 'bc'
Run Code Online (Sandbox Code Playgroud)
由于expensive_call("d")急切地进行了评估,因此请注意,即使next在第二次呼叫出现呼叫短路且输出为“ bc”的情况下,也会打印“ d ”。
我正在对列表中的调用进行硬编码a,而a不必是列表数据结构。
一种可能的解决方案如下:
a = ['expensive_call("a")', 'expensive_call_2("b", "c")', 'expensive_call("d")']
def generator():
for e in a:
r = eval(e)
if r is not None:
yield …Run Code Online (Sandbox Code Playgroud) java ×3
python ×3
swing ×3
layout ×2
python-3.x ×2
build ×1
bundler ×1
coffeescript ×1
docker ×1
forms ×1
immutability ×1
javafx ×1
javascript ×1
jtabbedpane ×1
linux ×1
list ×1
meteor ×1
mocha.js ×1
sbt ×1
scala ×1
server ×1
testing ×1
ubuntu-16.04 ×1
yield ×1