我在每个my-progress中定义了计时器,用于更新视图的值,但控制台显示常量变化的值,并且视图的值仍未更改,我该如何在计时器中更改值观点
Vue.component('my-progress', {
template: '\
<div class="progress progress-bar-vertical" data-toggle="tooltip" data-placement="top">\
<div class="progress-bar" role="progressbar" aria-valuenow="0" aria-valuemin="0" aria-valuemax="100" :style="{height: pgvalue}">{{pgvalue}}\
</div>\
</div>\
',
data : function(){
return {
pgvalue : '50%',
intervalid1:'',
}
},
computed:{
changes : {
get : function(){
return this.pgvalue;
},
set : function(v){
this.pgvalue = v;
}
}
},
mounted : function(){
this.todo()
},
beforeDestroy () {
clearInterval(this.intervalid1)
},
methods : {
todo : function(){
this.intervalid1 = setInterval(function(){
this.changes = ((Math.random() * 100).toFixed(2))+'%';
console.log (this.changes);
}, 3000);
} …Run Code Online (Sandbox Code Playgroud) 我看到了我不理解的Python行为.考虑这个布局:
project
| main.py
| test1.py
| test2.py
| config.py
Run Code Online (Sandbox Code Playgroud)
main.py:
import config as conf
import test1
import test2
print(conf.test_var)
test1.test1()
print(conf.test_var)
test2.test2()
Run Code Online (Sandbox Code Playgroud)
test1.py:
import config as conf
def test1():
conf.test_var = 'test1'
Run Code Online (Sandbox Code Playgroud)
test2.py:
import config as conf
def test2():
print(conf.test_var)
Run Code Online (Sandbox Code Playgroud)
config.py:
test_var = 'initial_value'
Run Code Online (Sandbox Code Playgroud)
所以,python main.py生产:
initial_value
test1
test1
Run Code Online (Sandbox Code Playgroud)
我对最后一行感到困惑.我认为,这将打印initial_value,因为我再次导入config.py在test2.py再次,我认为,我在上一步中所做的更改将被覆盖.我误会了什么吗?
我想测试是否可以从两个线程追加到列表,但是输出混乱:
import threading
class myThread(threading.Thread):
def __init__(self, name, alist):
threading.Thread.__init__(self)
self.alist = alist
def run(self):
print "Starting " + self.name
append_to_list(self.alist, 2)
print "Exiting " + self.name
print self.alist
def append_to_list(alist, counter):
while counter:
alist.append(alist[-1]+1)
counter -= 1
alist = [1, 2]
# Create new threads
thread1 = myThread("Thread-1", alist)
thread2 = myThread("Thread-2", alist)
# Start new Threads
thread1.start()
thread2.start()
print "Exiting Main Thread"
print alist
Run Code Online (Sandbox Code Playgroud)
所以输出是:
Starting Thread-1
Exiting Thread-1
Starting Thread-2
Exiting Main Thread
Exiting Thread-2
[1[1, 2[, …Run Code Online (Sandbox Code Playgroud) 我正在尝试测试wagtail RawHTMLBlock,这是我的代码(models.py):
from __future__ import absolute_import, unicode_literals
from wagtail.wagtailcore import blocks
from wagtail.wagtailcore.fields import StreamField
from wagtail.wagtailcore.models import Page
from wagtail.wagtailadmin.edit_handlers import FieldPanel
class HomePage(Page):
body = StreamField([
('raw_html', blocks.RawHTMLBlock()),
])
content_panels = Page.content_panels + [
FieldPanel('body')
]
Run Code Online (Sandbox Code Playgroud)
现在我正在尝试添加一个主页并在我网站的管理部分向正文添加一些 html,但我无法这样做,因为我在chrome's控制台中收到此 js 错误:
stream.js:87 Uncaught TypeError: Cannot read property 'initializer' of undefined
at Object.onInitializeMember (stream.js:87)
at postInsertMember (sequence.js:95)
at Object.self.insertMemberAtStart (sequence.js:196)
at Object.onChooseBlock (stream.js:140)
at HTMLButtonElement.<anonymous> (stream.js:60)
at HTMLButtonElement.dispatch (jquery-2.2.1.min.js:3)
at HTMLButtonElement.r.handle (jquery-2.2.1.min.js:3)
Run Code Online (Sandbox Code Playgroud)
wagtail 版本是1.13.1,有什么想法吗?
def multipliers():
return [lambda x: i * x for i in range(4)]
print([m(1) for m in multipliers()]) # [3, 3, 3, 3]
Run Code Online (Sandbox Code Playgroud)
为什么不是[0, 1, 2, 3]?无法理解。那么,出于某种原因,我们i = 3在所有 lambda 表达式中都有?为什么?
我试图理解这个问题和答案:
为了理解它,我尝试:
def f1(a, L=[]):
if not L:
print "L is empty"
L = []
L.append(a)
return L
>>>f1(1)
L is empty
[1]
>>>f1(1)
L is empty
[1]
def f2(a, L=[]):
if L:
print "L isn't empty"
L = []
L.append(a)
return L
>>>f2(1)
[1]
>>>f2(1)
L isn't empty
[1]
Run Code Online (Sandbox Code Playgroud)
因此,我认为在f1 L每次再次变空的情况下- []在每次调用之后再次分配f1.但是,如果f2 L是某种程度上不是空的?为什么?