我有一个类似于下面的类结构.sqlalchemy使用db.create_all创建的表看起来不错.添加了相应列的作业(教师的school_id,警察的precinct_id).尝试调用do_stuff()时出现问题:
p = Teacher(...)
p.do_stuff()
Run Code Online (Sandbox Code Playgroud)
返回"hey im the parent",这是Job的返回值.因此,即使所有内容都正确地插入到数据库中,看起来实际的继承似乎没有发生,而是唯一的模型就是作业模型.有没有办法解决这个问题,还是应该以另一种方式设置?
class Job(db.Model):
id = Column(Integer, primary_key=True)
...
def __init__(...):
...
def do_stuff(self):
print 'hey im the parent'
class Teacher(Job):
school_id = Column(Integer, ForeignKey('school.id'))
def __init__(...):
super(Teacher, self).__init__(...)
self.school_id = school_id
def do_stuff(self):
print 'teacher here'
class Policeman(Job):
precinct_id = Column(Integer, ForeignKey'precinct.id'))
def __init__(...):
super(Policeman, self).__init__(...)
self.precinct_id = precinct_id
def do_stuff(self):
print 'police ack'
Run Code Online (Sandbox Code Playgroud) 我在超类中有一个函数,它返回一个自己的新版本.我有一个继承特定函数的超类的子类,但宁愿它返回子类的新版本.我如何对其进行编码,以便当函数调用来自父级时,它返回父级的版本,但是当从子级调用它时,它会返回子级的新版本?
我制作了一个使用AVAudioPlayer播放音乐的应用程序.它可以上传或下载歌曲,将它们写入Core Data,然后在选择时调用它们进行播放.我一直在测试的所有15首歌曲都使用iPhone音乐客户端和我自己的电脑正常运行.
但是,其中三个不回放应用程序.具体来说,我可以按任意顺序上传这15首歌曲,清除我的Model.sqlite,再次将它们下载到应用程序中,并发现其中三首不播放.然而,他们确实拥有正确的头衔和艺术家.
考虑到这一点,我注意到不同的是,非工作文件是.m4a.如何使用AVAudioPlayer播放该格式的文件?
编辑("Whats"回忆?",你用什么URL初始化AVAudioPlayer?"):
有一个服务器,其中包含用户可以通过应用程序访问的歌曲.在选择要检索的子集S之后,应用程序然后下载S并使用NSManagedObjectContext将其写入CoreModel.每首歌曲作为单独的实体存储,具有唯一ID和与子集实体的关系(在本例中为S).
当我"回忆"使用AppDelegate使用上下文获取正确的歌曲时,也会返回数据.然后我像这样初始化AVAudioPlayer:
[[AVAudioPlayer alloc] initWithData:(NSData *)[currentSong valueForKey:@"data"] error:nil];
Run Code Online (Sandbox Code Playgroud)
...所以我写了那个,然后意识到我实际上没有检查出错误是什么(愚蠢的我).我发现它是OSStatus error 1954115647,它返回为不支持的文件类型.再看看这个,我发现这个iPhone:AVAudioPlayer不支持的文件类型.在那里提出了一种解决方案,即在开始时修剪坏数据或从URL的内容初始化.是否有可能在核心模型中找到数据的写入位置以将其作为URL提供?
编辑:(比较文件.它们有什么不同吗?)
对,他们是.我从我的服务器抓取一个样本.m4a文件,该文件由应用程序上传,并将其与iTunes中的文件进行比较.我发现该文件在偏移229404(超出2906191字节)之前被切断,从而开始20680001 A0000E21.在iTunes版本中,0028D83B 6D646174位于这些字节之前.在此之前是一大块零,之后是iTunes编码信息之前的大数据块.最顶层的是更多编码信息,将文件列为M4A.
我有一个简单的设置,使用如下所示的flask-login.当我点击before_request时,g.user设置正确.我也正确注册用户(因为他们使用正确的电子邮件/通行证打到数据库).我的问题是在before_request和页面命中之间,g.user总是变为None.我想我会错过会话,但我不知道是什么.
init:
lm = LoginManager()
lm.init_app(app)
lm.login_view = 'login'
Run Code Online (Sandbox Code Playgroud)
在view/login.py文件中,我有以下内容.
意见/ login.py:
@app.lm.user_loader
def load_user(id):
return models.user.user_with_id(id)
@app.before_request
def before_request():
g.user = current_user
print 'current_user: %s, g.user: %s, leaving bef_req' % (current_user, g.user)
@app.route('/login', methods=['GET', 'POST'])
def login():
print 'in login, g.user: %s' % g.user
if g.user is not None and g.user.is_authenticated():
return redirect(url_for('index'))
enter_form = app.forms.EnterForm()
if enter_form.validate_on_submit():
session['remember_me'] = True
return app.models.user.try_register(enter_form.email.data,
enter_form.password.data)
return render_template('index.html', enter_form=enter_form, profiles=[])
Run Code Online (Sandbox Code Playgroud)
意见/ index.py:
@app.route('/', methods=['GET', 'POST'])
@app.route('/index', methods=['GET', 'POST'])
def index(): …Run Code Online (Sandbox Code Playgroud) 我的问题是我使用 FormData 向服务器发送一个 Blob,但服务器没有得到它。代码如下所示:
Flask 服务器代码:
@app.route('/save-record', methods=['POST'])
def save_record():
app.logger.debug(request.form.keys()) #Shows only the title key, not the file key
Run Code Online (Sandbox Code Playgroud)
客户端JS代码:
var save = function() {
var form = new FormData();
form.append('file', record.blob, record.filename);
form.append('title', searchedObj.title);
//Chrome inspector shows that the post data includes a file and a title.
$.ajax({
type: 'POST',
url: '/save-record',
data: form,
cache: false,
processData: false,
contentType: false
}).done(function(data) {
console.log(data);
});
Run Code Online (Sandbox Code Playgroud) 请在下面查看我的搜索查询,以下是具体问题。
search = {
'query' : {
'function_score': {
'score_mode': 'multiply'
'functions': functions,
'query': {
'match_all':{}
},
'filter': {
'bool': {
'must': filters_include,
'must_not': filters_exclude
}
}
}
}
'sort': [{'_score': {'order': 'desc'}},
{'time': {'order': 'desc'}}]
}
Run Code Online (Sandbox Code Playgroud)
其中functions的样子:
[{'weight': 5.0, 'gauss': {'time': {'scale': '7d'}}},
{'weight': 3.0, 'script_score': {'script': "1+doc['scores.year'].value"}},
{'weight': 2.0, 'script_score': {'script': "1+doc['scores.month'].value"}}]
Run Code Online (Sandbox Code Playgroud)
运行此查询时会发生什么情况?文档是否由function_score评分,然后根据事实与sort数组进行排序?_score现在是什么(请注意查询是match_all),它在排序中有什么作用?如果我将其颠倒并放在time前面_score,我应该期待什么结果?
我正在与gmail api交谈,并希望批量处理请求.他们有一个友好的指南,https://developers.google.com/gmail/api/guides/batch,这表明我应该能够使用multipart/mixed并包含不同的网址.
我正在使用Python和Requests库,但我不确定如何发布不同的URL.像这样的答案如何在python中发送带有请求的"multipart/form-data"?不要提及更改该部分的选项.
我该怎么做呢?
我很好奇List.updated.什么是运行时?它与仅仅更改ArrayBuffer中的一个元素相比如何?在后台,它如何处理复制所有列表?这是一个O(n)程序吗?如果是这样,是否存在一个不可变的数据结构,它具有更新的类似方法,而不是那么慢?
一个例子是:
val list = List(1,2,3)
val list2 = list.updated(2, 5) --> # list2 = (1,5,3)
var abuf = ArrayBuffer(1,2,3)
abuf(2) = 5 --> # abuf = (1,5,3)
Run Code Online (Sandbox Code Playgroud) 我有一个矩阵中的值列表,其中维度是一天一天(因此每个值代表一周中的特定日期).这几周是按顺序递增的,日期由他们的名字定义(例如"星期五").
我想把它变成一个情节,并且我认为最好的方法是解开它,以便矩阵中的值按日历顺序列出,从指定日期开始.
例:
Friday Monday Thursday
w1 5 3 2
w2 1 7 1
w3 2 10 9
Run Code Online (Sandbox Code Playgroud)
- >(星期一):( 3,2,5,7,1,1,10,9,2)
我如何在R中干净利落地做到这一点?如果您对如何更好地呈现数据有另一个想法,请说出来.
我希望拍摄一段视频并以类似于 Instagram 使用的压缩方式对其进行压缩。什么 ffmpeg 命令可以做到这一点?
flask ×3
python ×3
inheritance ×2
blob ×1
compression ×1
ffmpeg ×1
form-data ×1
gmail-api ×1
immutability ×1
instagram ×1
ios ×1
javascript ×1
m4a ×1
r ×1
scala ×1
session ×1
sorting ×1
sqlalchemy ×1