要连接到 GCE,我可以使用由gcloud auth login创建的凭据文件。像这样:
from oauth2client.client import GoogleCredentials
from googleapiclient.discovery import build
credentials = GoogleCredentials.get_application_default()
compute = build('compute', 'v1', credentials=credentials)
def list_instances(compute, project, zone):
result = compute.instances().list(project=project, zone=zone).execute()
return result['items']
instances = list_instances(compute, 'project', 'zone')
Run Code Online (Sandbox Code Playgroud)
上面的代码使用存储在 ~/.config/gcloud 的凭据
我想通过直接在代码中设置值来初始化 GoogleCredentials 对象。像client_id,client_secret..
PS:以上代码来自此链接:https : //cloud.google.com/compute/docs/tutorials/python-guide#gettingstarted
我在弹性搜索中有一个索引。
样品结构:
{
"Article": "Article7645674712",
"Genre": "Genre92231455",
"relationDesc": [
"Article",
"Genre"
],
"org": "user",
"dateCreated": {
"date": "08/05/2015",
"time": "16:22 IST"
},
"dateModified": "08/05/2015"
}
Run Code Online (Sandbox Code Playgroud)
我想从该索引中检索选定的字段:org和dateModified。
我想要这样的结果
{
"took": 265,
"timed_out": false,
"_shards": {
"total": 5,
"successful": 5,
"failed": 0
},
"hits": {
"total": 28,
"max_score": 1,
"hits": [
{
"_index": "couchrecords",
"_type": "couchbaseDocument",
"_id": "3",
"_score": 1,
"_source": {
"doc": {
"org": "user",
"dateModified": "08/05/2015"
}
}
},
{
"_index": "couchrecords",
"_type": "couchbaseDocument",
"_id": "4", …Run Code Online (Sandbox Code Playgroud) BigDecimal b = new BigDecimal(0.05);
System.out.println(b);
Run Code Online (Sandbox Code Playgroud)
输出:
0.05000000000000000277555756156289135105907917022705078125
Run Code Online (Sandbox Code Playgroud)
这要怎么处理呢?
两天前设置运行正常.从那以后我关闭了mongo连接器,mongo-db在后台运行.但我没有对mongo运行任何查询.
现在我尝试今天早上启动mongo-connector并且无法启动.
viki@viki-pc:~/Documents/elasticSearch$ mongo-connector -m localhost:27017 -t localhost:9200 -d /usr/local/lib/python2.7/dist-packages/mongo_connector/doc_managers/elastic_doc_manager.py
2014-12-08 11:43:49,870 - INFO - Beginning Mongo Connector
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/lib/python2.7/threading.py", line 810, in __bootstrap_inner
self.run()
File "/usr/local/lib/python2.7/dist-packages/mongo_connector/connector.py", line 284, in run
self.read_oplog_progress()
File "/usr/local/lib/python2.7/dist-packages/mongo_connector/connector.py", line 271, in read_oplog_progress
if not isinstance(data[0], list):
IndexError: list index out of range
Run Code Online (Sandbox Code Playgroud)
我试图用弹性搜索连接mongo.它在2天前工作正常.
我正在我的Ubuntu 14.10中安装Tensorflow.我以前安装了numpy,scipy,sklearn和ipython-notebook.我按照Tensorflow.org上的官方文档(pip安装).我的tensorflow安装目录的位置是/usr/local/lib/python2.7/dist-packages.我import tensorflow as ts在Ubuntu终端中执行时出现以下错误.
>>> import tensorflow as tf
RuntimeError: module compiled against API version 0xa but this version of numpy is 0x9
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/tensorflow/__init__.py", line 24, in <module>
from tensorflow.python import *
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 60, in <module>
raise ImportError(msg)
ImportError: Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/tensorflow/python/__init__.py", line 49, in <module>
from …Run Code Online (Sandbox Code Playgroud) 我正在使用elasticsearch dsl搜索elasticsearch:https : //elasticsearch-dsl.readthedocs.org/en/latest/
如何为查询启用track_scores?
我知道它在Elasticsearch中受支持:https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-sort.html#_track_scores
只是不知道如何在Elasticsearch-dsl中做同样的事情
我想,以取代'.net'在'i like .net'用.NET.预期产量:'i like .NET'.
同样'c++'在'i like c++'用Cpp.预期产量:'i like Cpp'.
有更多特殊字符的情况,如'c ++'
import re
regex_match = re.compile(r'\bnet\b')
print(regex_match.sub('NET', 'I like .net'))
# output I like .NET Which works but I need boundary match also.
regex_match = re.compile(r'\b.net\b')
print(regex_match.sub('NET', 'I like .net'))
# output I like .net
regex_match = re.compile(r'\b\.net\b')
print(regex_match.sub('NET', 'I like .net'))
# output I like .net
regex_match = re.compile(r'\b' + re.escape('.net') + '\b')
print(regex_match.sub('NET', …Run Code Online (Sandbox Code Playgroud) python ×4
bigdecimal ×1
java ×1
mongodb ×1
numpy ×1
python-2.7 ×1
regex ×1
tensorflow ×1
ubuntu ×1