谁能解释一下如何将 SSL 添加到我正在使用的 Python STOMP 客户端。我在 ActiveMQ 配置文件中添加了 stomp+ssl 传输连接器,我的基本 Python STOMP 客户端如下:
import time
import sys
import stomp
class MyListener(stomp.ConnectionListener):
def on_error(self, headers, message):
print('received an error "%s"' % message)
def on_message(self, headers, message):
print('received a message "%s"' % message)
conn = stomp.Connection()
conn.set_listener('', MyListener())
conn.start()
conn.connect('admin', 'password', wait=True)
conn.subscribe(destination='/queue/test', id=1, ack='auto')
conn.send(body=' '.join(sys.argv[1:]), destination='/queue/test')
time.sleep(2)
conn.disconnect()
Run Code Online (Sandbox Code Playgroud)
我创建了http://activemq.apache.org/how-do-i-use-ssl.html文档中给出的密钥库和信任库,并将它们添加到SSL_OPTS代理中的环境变量中,但我找不到如何使用密钥库和信任库初始化 Python STOMP 客户端。我是否应该使用stomp.Connection()方法中给出的 SSL 参数,如果是,如何使用?
谁能解释一下是否还有其他方法可以通过 STOMP 添加 SSL?
我试图在 Altair 中创建时间范围跨越几天的时间序列图的 Vega-Lite 规范。由于在我的情况下,很清楚哪一天是哪一天,我想通过让标签的形式为 来减少轴标签中的噪音'%H:%M',即使这会导致标签不明显。
这是一些示例数据;我的实际数据有五分钟的分辨率,但我想这在这里不会太重要:
import altair as alt
import numpy as np
import pandas as pd
# Create data spanning 30 hours, or just over one full day
df = pd.DataFrame({'time': pd.date_range('2018-01-01', periods=30, freq='H'),
'data': np.arange(30)**.5})
Run Code Online (Sandbox Code Playgroud)
通过使用其他微不足道的yearmonthdatehoursminutes变换,我得到以下信息:
alt.Chart(df).mark_line().encode(x='yearmonthdatehoursminutes(time):T',
y='data:Q')
Run Code Online (Sandbox Code Playgroud)
现在,我的目标是去掉水平轴标签中的日期,让它们变成类似['00:00', '03:00', ..., '21:00', '00:00', '03:00'],或者任何间距效果最好的东西。
仅用hoursminutes作转换的幼稚方法是行不通的,因为它会存储实际数据:
alt.Chart(df).mark_line().encode(x='hoursminutes(time):T', y='data:Q')
Run Code Online (Sandbox Code Playgroud)
那么,有没有一种声明式的方式来做到这一点?最终,可视化将利用选择来定义水平轴限制,因此明确使用指定标签Axis似乎并不吸引人。
通过
import win32com.client
wordapp = win32com.client.gencache.EnsureDispatch('Word.Application')
Run Code Online (Sandbox Code Playgroud)
我可以在这里Application记录一个Word 对象.但是,自动完成功能并不知道该API,有没有办法添加它?ipython
我正在使用Git Bash使用$ python3 -m http.server 8000运行一个简单的本地服务器
Git Bash从不打印其正在运行,并且不会获取请求的日志。我可以访问http:// localhost:8000 /,因此该命令有效。如何获取git bash打印日志?
我在解释Tfidf矢量化器的矩阵输出时遇到了麻烦.
特定
vectorizer = TfidfVectorizer(max_df=0.5, max_features=10000,
min_df=2, stop_words='english',
use_idf=True)
X_train_tfidf = vectorizer.fit_transform(X_train_raw)
Run Code Online (Sandbox Code Playgroud)
如果我要查看输出X_train_tfidf,我是否正在查看结构如下的矩阵:
第1列对应于文档1,其中元素是10000个特征的tfidf分数,第2列对应于文档2 ......依此类推?
我正在尝试使用Sklearn提取特征提取文本,但是出现错误
类型错误:fit_transform()缺少1个必需的位置参数:“ raw_documents”
似乎我必须在缺少原始文档的情况下完成一些参数,但是我找不到导致错误的原因,这是我的代码:
features=TfidfVectorizer.fit_transform(data.status).toarray()
label=data.label
features.shape
Run Code Online (Sandbox Code Playgroud)
在Jupyter笔记本电脑控制台中运行时,出现以下错误:
TypeError Traceback (most recent call last)\
<ipython-input-3-614f2fa78a04> in <module>()
----> 1 features=TfidfVectorizer.fit_transform(data.status).toarray()
2 label=data.label
3 features.shape
TypeError: fit_transform() missing 1 required positional argument: 'raw_documents'
Run Code Online (Sandbox Code Playgroud) python machine-learning feature-extraction scikit-learn tfidfvectorizer
我知道这个问题被问了十几次,但我在我的具体例子中需要帮助。我只是不知道为什么它不起作用。
最后我想要 150 条不同的行,但现在我只想用 10 行来测试它。
目的是遍历颜色图,我的代码如下所示:
import matplotlib.pyplot as plt
jet= plt.get_cmap('jet')
colors = iter(jet(np.linspace(0,1,10)))
for k in range(0,10):
plt.plot(u_ordered[0*k:42*(k+1)], T_ordered[0*k:42*(k+1)], 'o',
color=next(colors))
plt.xscale('log')
plt.ylabel('T [K]')
plt.xlabel('log u [KJ/g]')
plt.title('T - U (at const. Rho) Plot')
plt.legend(loc="lower right")
plt.savefig('T_u_const_rho_Plot1.pdf')
plt.show()
Run Code Online (Sandbox Code Playgroud)
我很惊讶 networkx 似乎没有内置函数来做到这一点,但也许我错过了一些使用内置算法来做到这一点的聪明方法?
下面的代码实现了O(n ^ 2)的时间复杂度.我希望能够在O(n)中完成.
例如,给定数组[-2,1,-3,4,-1,2,1,-5,4],连续子阵列[4,-1,2,1]具有最大的和= 6.
def maximum_sub_array(arr, n):
ans = - sys.maxint - 1
for start_index in range(0, n):
_sum = 0
for sub_array_size in range(1,n+1):
if (start_index + sub_array_size > n): # Subarray exceeds array bounds
break
_sum += arr[start_index + sub_array_size -1] # Last element of the new Subarray
ans = max(ans, _sum)
return ans
Run Code Online (Sandbox Code Playgroud) 我想在通过 win32com 创建的任务正文中创建一个超链接。
到目前为止,这是我的代码:
outlook = win32com.client.Dispatch("Outlook.Application")
outlook_task_item = 3
recipient = "my_email@site.com"
task = outlook.CreateItem(outlook_task_item)
task.Subject = "hello world"
task.Body = "please update the file here"
task.DueDate = dt.datetime.today()
task.ReminderTime = dt.datetime.today()
task.ReminderSet = True
task.Save()
Run Code Online (Sandbox Code Playgroud)
我尝试设置该属性task.HTMLBody,但收到错误:
AttributeError: Property 'CreateItem.HTMLBody' can not be set.
Run Code Online (Sandbox Code Playgroud)
我也尝试过
task.Body = "Here is the <a href='http://www.python.org'>link</a> I need"
Run Code Online (Sandbox Code Playgroud)
但我没有得到正确的超链接。
但是,如果我在 Outlook 中创建任务前端,我就可以添加超链接。
python ×10
scikit-learn ×2
win32com ×2
algorithm ×1
altair ×1
autocomplete ×1
colors ×1
git-bash ×1
graph-theory ×1
ipython ×1
matplotlib ×1
matrix ×1
mingw ×1
networkx ×1
outlook ×1
plot ×1
ssl ×1
stomp ×1
stomp.py ×1
tf-idf ×1
time-series ×1
vega-lite ×1