我有一个组件调用服务从RESTful端点获取数据.该服务需要被赋予回调函数以在获取所述数据之后执行.
问题是当我尝试使用回调函数将数据附加到组件变量中的现有数据时,我得到了一个EXCEPTION: TypeError: Cannot read property 'messages' of undefined.为什么不this定义?
TypeScript版本:版本1.8.10
控制器代码:
import {Component} from '@angular/core'
import {ApiService} from '...'
@Component({
...
})
export class MainComponent {
private messages: Array<any>;
constructor(private apiService: ApiService){}
getMessages(){
this.apiService.getMessages(gotMessages);
}
gotMessages(messagesFromApi){
messagesFromApi.forEach((m) => {
this.messages.push(m) // EXCEPTION: TypeError: Cannot read property 'messages' of undefined
})
}
}
Run Code Online (Sandbox Code Playgroud) 我正在Google Cloud Functions上试用Python3.7运行时。我能够部署功能并使它们一旦部署就可以工作,但是,在部署之前,我似乎无法在本地运行模拟器来对其进行测试。
Google的文档有点不一致,他们告诉您在此处安装google函数模拟器:https : //cloud.google.com/functions/docs/emulator
但是在Firebase上,它们会告诉您npm installfirebase-admin,firebase-tools和firebase-functions。
所有仿真器文档都引用了用JS编写的示例,而没有使用Python编写的示例,因此我想知道这些仿真器是否甚至在本地运行Python函数?
谢谢
python-3.x firebase google-cloud-platform google-cloud-functions
可以在GAE上使用MlPy/SciPy吗?
我相信我已正确导入NumPy,因为它到目前为止没有引起任何错误(GAE 1.6支持NumPy).但是,从我读过的内容来看,我仍然需要导入SciPy和MlPy,到目前为止我还没能做到.是否有任何文件可以准确解释如何在GAE上设置MlPy(如果这是可能的话)?
我需要MlPy的主要原因是我需要进行k均值分析(找到一个聚类中心点).是不是有一个"精简"库可以避免设置NumPy和MlPy的所有麻烦?
谢谢.
编辑:
我正在尝试导入scipy.我做的是:
我得到的错误是:
ImportError: Error importing scipy: you cannot import scipy while
being in scipy source directory; please exit the scipy source
tree first, and relaunch your python intepreter.
Run Code Online (Sandbox Code Playgroud) 我在GoogleAppEngine上使用NDB,我想通过将电子邮件传递给查询来检索实例密钥或ID.
我的模型看起来像这样:
class Users(ndb.Model):
user_name = ndb.StringProperty(required=True)
user_email = ndb.StringProperty(required=True)
user_password = ndb.StringProperty(required=True)
@classmethod
def get_password_by_email(cls, email):
return Users.query(Users.user_email == email).get(projection=[Users.key, Users.user_password])
Run Code Online (Sandbox Code Playgroud)
运行代码时,我收到以下错误:
BadProjectionError: Projecting on unknown property __key__
Run Code Online (Sandbox Code Playgroud)
如何通过AppEngine的NDB中的电子邮件查询用户(例如登录过程)来获取实例ID或密钥?
谢谢!
我基本上想要使用MatchScore对文档进行排序,但是,请提升那些拥有图像的文档.
为此,我的方法是使用提升值向文档添加字段,然后将此值乘以文档_score.
问题是,使用以下代码我无法实现基于两个值的乘法对文档进行排序.Search API返回按_score排序的文档,而不是我传递的SortOptions表达式.
sort_opts = SortOptions(
match_scorer=search.MatchScorer(),
expressions=[
search.SortExpression(
expression='_score * has_img',
direction=search.SortExpression.DESCENDING,
default_value=0.0
)
]
)
options = QueryOptions(
limit=10,
sort_options=sort_opts,
returned_expressions=[
FieldExpression('score', '_score * has_img'),
FieldExpression('normalscore', '_score * 1')
]
)
index = search.Index(name='Search', namespace='search')
results = index.search(
query=Query(
query_string=search_query,
options=options
)
)
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,为了进行调试,我返回了我想要排序的分数以及默认分数.但它们会返回正确的值,但文档仍按默认分数排序.
我做错了什么想法?
sorting google-app-engine boost google-search-api python-2.7
通过阅读各种帖子,似乎JavaScript unescape()相当于Pythons urllib.unquote(),但是当我测试两者时,我会得到不同的结果:
unescape('%u003c%u0062%u0072%u003e');
Run Code Online (Sandbox Code Playgroud)
输出: <br>
import urllib
urllib.unquote('%u003c%u0062%u0072%u003e')
Run Code Online (Sandbox Code Playgroud)
输出: %u003c%u0062%u0072%u003e
我希望Python也能回归<br>.关于我在这里缺少什么的想法?
谢谢!
我已经在生产中收集了一些数据,比如说,以下模型:
class Tags(ndb.Model):
dt_added = ndb.DateTimeProperty(auto_now_add=True)
s_name = ndb.StringProperty(required=True, indexed=True)
Run Code Online (Sandbox Code Playgroud)
想象一下,我现在为模型添加一个新属性:
class Foo(ndb.Model):
is_valid = ndb.BooleanProperty(default=False)
some_key = ndb.KeyProperty(repeated=True)
class Tags(ndb.Model):
dt_added = ndb.DateTimeProperty(auto_now_add=True)
name = ndb.StringProperty(required=True, indexed=True)
new_prop = ndb.StructuredProperty(Foo)
Run Code Online (Sandbox Code Playgroud)
...并使用这个新模型收集更多数据.
所以现在我有一部分属性new_prop设置的数据,另一部分没有设置.
我的问题是:如何使用未new_prop设置的新属性查询数据?
我试过了:
query_tags = Tags.query(Tags.new_prop == None).fetch()
Run Code Online (Sandbox Code Playgroud)
但似乎没有设置该属性的数据...任何建议?谢谢!
python google-app-engine app-engine-ndb google-cloud-datastore
在最近的 SDK 更新中,Google 似乎在 dev_appserver 中添加了 INFO 级别日志,每次检测到文件更改时都会打印出来。
在我看来,这只会用我已经知道的信息弄乱日志,因此我不希望将其打印在我的控制台上。
INFO 2014-11-27 09:52:43,876 module.py:391] [default] Detected file changes:
/Users/michael/app/templates/home
/Users/michael/app/templates/home/index.html
Run Code Online (Sandbox Code Playgroud)
有什么办法可以从日志中删除这些行吗?由于这是一个 INFO 级别日志,我无法真正从 log_level 中删除 INFO,因为其他 INFO 日志多次派上用场......
有什么建议么?
在尖锐物体上调用该.toBuffer()方法时,出现以下错误:
Input buffer contains unsupported image format
Run Code Online (Sandbox Code Playgroud)
我正在从 S3 获取图像,并且我确信它会作为缓冲区检索,然后传递给 Sharp。
此外,当我console.log缓冲区的base64并检查后面的内容时,我确实得到了原始图像并且文件类型是jpeg,所以我似乎无法弄清楚为什么它会说输入缓冲区包含不支持的图像格式。
const imageBuffer = fileFromS3.Body
console.log(imageBuffer)
console.log(imageBuffer.toString('base64'))
let result = await sharp(imageBuffer)
.toColourspace('b-w')
.sharpen()
.toBuffer()
Run Code Online (Sandbox Code Playgroud)
当我在运行 toBuffer() 之前检查尖锐对象时,我在对象中获取了以下数据:
let result = await sharp(imageBuffer)
.toColourspace('b-w')
.sharpen()
console.log(result)
Run Code Online (Sandbox Code Playgroud)
印刷:
...
input: {
failOnError: true,
limitInputPixels: 268402689,
sequentialRead: false,
buffer: <Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 02 …Run Code Online (Sandbox Code Playgroud) 我想创建一个布局,其中我有类似于 BoxLayout 的东西,让我能够在我的布局中创建“行”,并且在每个“行”中,我想使用另一种 BoxLayout 中的某些东西来创建“列” .
列不需要均匀分布。例如,我想创建一个 BoxLayout,其中一列带有方形图像,另一列占据可用宽度的其余部分。
请参阅我的要点上的代码和屏幕截图:https : //gist.github.com/MichaelGradek/e5c50038b947352d9e79
我已经在上面的代码中完成了基本结构,但另外,我希望 BoxLayout 的高度适应孩子们的高度。
实现这一目标的最佳方法是什么?
谢谢!
python ×4
javascript ×2
python-2.7 ×2
angular ×1
arrays ×1
boost ×1
escaping ×1
firebase ×1
kivy ×1
node.js ×1
numpy ×1
python-3.x ×1
scipy ×1
sharp ×1
sorting ×1
typescript ×1
urllib ×1