我正在学习xtend.在xtend中创建逗号分隔列表的好方法是什么?(像xpand中的SEPARATOR)
我想在生成器中生成逗号分隔的参数列表:
«FOR param: row.params»
"«param.value»",
«ENDFOR»
Run Code Online (Sandbox Code Playgroud)
这有效,但我需要省略最后一个逗号.我也尝试了row.params.join(",")但是引号丢失了.
我从回溯中读取了获取最后一个函数的调用参数?但这还不够具体,无法回答我的问题。
这真的很困扰我,因为没有调用参数会减慢我的速度,而且我很确定可以从 Python 获取此类信息。
下面是一个例子来说明这个问题:
# -*- coding: utf-8 -*-
import sys
import traceback
import inspect
import logging as log
def fl(x):
# exception is happening here
y = 5/x
return y
def fm(x):
return fl(x-3)
def fn(a, b, c=None):
return fm(c)
def main():
try:
print fn(1, 2, c=3)
except Exception as e:
log.error('Unexpected problem.')
log.error(e)
traceback.print_exc()
### what I need to see is are the call arguments of the last / deepest call: ###
### …Run Code Online (Sandbox Code Playgroud) 我正在使用NewGaugeVec报告我的指标:
elapsed := prometheus.NewGaugeVec(prometheus.GaugeOpts{
Name: "gogrinder_elapsed_ms",
Help: "Current time elapsed of gogrinder teststep",
}, []string{"teststep", "user", "iteration", "timestamp"})
prometheus.MustRegister(elapsed)
Run Code Online (Sandbox Code Playgroud)
一切正常,但我注意到我的自定义导出器包含prometheus / go_collector.go中的所有指标:
# HELP go_gc_duration_seconds A summary of the GC invocation durations.
# TYPE go_gc_duration_seconds summary
go_gc_duration_seconds{quantile="0"} 0.00041795300000000004
go_gc_duration_seconds{quantile="0.25"} 0.00041795300000000004
go_gc_duration_seconds{quantile="0.5"} 0.00041795300000000004
...
Run Code Online (Sandbox Code Playgroud)
我怀疑这是一种默认行为,但是我没有在文档中找到如何禁用它的任何内容。关于如何配置自定义导出器以使这些默认指标消失的任何想法?
我通常会在 Golang 中找到 Reader 和 Writer,但我遇到了一个对我来说很陌生的情况。
我正在使用“golang.org/x/net/html”渲染。它输出到 Writer w。我想使用该输出并从中创建一个新请求。NewRequest 使用 Reader r。
err := html.Render(w, msg)
...
req, err := http.NewRequest("Post", url, r)
io.Copy(w, r)
Run Code Online (Sandbox Code Playgroud)
我的问题是“使用 w 和 r 绑定两个调用的最佳/理想解决方案是什么?”。我在网上找不到类似情况的示例。我正在考虑创建 Reader 和 Writer 并在它们上使用 io.Copy(w, r) 。我不确定,因为对于显然经常使用的东西来说,这似乎有点复杂。
我是熊猫新手,我认为尝试一下是个好主意,但第一次似乎并不那么容易。
我基本上尝试了以下方法: Pandas read in table without headers
我收到以下错误(不幸的是,Usecols 不匹配名称不会响铃,因为我将 header 设置为 None):
ValueError:Usecols 与名称不匹配。
这是我的代码:
import numpy as np
DATA_FOLDER = 'season_1/training_data/'
#data = np.loadtxt(DATA_FOLDER + 'order_data/order_data_sample',
# dtype={'names': ('order_id', 'driver_id', 'passenger_id', 'start_district_hash',
# 'dest_distric_hash', 'price', 'time'),
#... 'formats': ('S32', 'S32', 'S32', 'S32', 'S32', 'f6', 'f4')})
import pandas as pd
df = pd.read_csv(DATA_FOLDER + 'order_data/order_data_sample', parse_dates=[6], header=None, usecols=[3, 4, 6])
df
Run Code Online (Sandbox Code Playgroud)
和我的数据:
97ebd0c6680f7c0535dbfdead6e51b4b dd65fa250fca2833a3a8c16d2cf0457c ed180d7daf639d936f1aeae4f7fb482f 4725c39a5e5f4c188d382da3910b3f3f 3e12208dd0be281c92a6ab57d9a6fb32 24 2016-01-01 13:37:23
92c3ac9251cc9b5aab90b114a1e363be c077e0297639edcb1df6189e8cda2c3d 191a180f0a262aff3267775c4fac8972 82cc4851f9e4faa4e54309f8bb73fd7c b05379ac3f9b7d99370d443cfd5dcc28 2 2016-01-01 …Run Code Online (Sandbox Code Playgroud) 我目前对如何以有效的方式做到这一点空白.我想过使用对象,但我不知道在这种情况下他们如何能够提供帮助.有任何想法吗?
from random import choice
from copy import deepcopy
def main():
def rand_int():
return choice(['yes', 'no'])
# any nesting, functions possible
spec = {
'answer': rand_int,
'next': {'answer': rand_int},
'the_answer': 42
}
#### looking for elegant (automatic) way to do this
result = deepcopy(spec)
result['answer'] = result['answer']()
result['next']['answer'] = result['next']['answer']()
#### until here
# result2 = ...
print 'result: %s' % result
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
请不要告诉我使用xsd!
python ×3
go ×2
csv ×1
dataframe ×1
dictionary ×1
exception ×1
jupyter ×1
monitoring ×1
pandas ×1
prometheus ×1
stack-trace ×1
xtend ×1