我使用v2进行了演示,现在我想使用v3.
但我发现v3没有v2那么多的方法,例如:
map.enableGoogleBar();
map.enableScrollWheelZoom();
polyline.enableDrawing()
那么,v3强大到足以取代v2 ???
from threading import Timer
def hello():
print "hello, world"
t = Timer(30.0, hello)
t.start()
Run Code Online (Sandbox Code Playgroud)
此代码仅触发计时器一次.
如何让计时器永远运行?
谢谢,
更新
这是正确的 :
import time,sys
def hello():
while True:
print "Hello, Word!"
sys.stdout.flush()
time.sleep(2.0)
hello()
Run Code Online (Sandbox Code Playgroud)
还有这个:
from threading import Timer
def hello():
print "hello, world"
sys.stdout.flush()
t = Timer(2.0, hello)
t.start()
t = Timer(2.0, hello)
t.start()
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
def a():
print 'sss'
@a()
def b():
print 'aaa'
b()
Run Code Online (Sandbox Code Playgroud)
跟踪是:
sss
Traceback (most recent call last):
File "D:\zjm_code\a.py", line 8, in <module>
@a()
TypeError: 'NoneType' object is not callable
Run Code Online (Sandbox Code Playgroud)
那么如何使用'@'
谢谢
更新
class a:
@property
def b(x):
print 'sss'
aa=a()
print aa.b
Run Code Online (Sandbox Code Playgroud)
它打印:
sss
None
Run Code Online (Sandbox Code Playgroud)
如何使用@property
谢谢
updated2
和类方法:
class a:
@classmethod
def b(x):
print 'sss'
aa=a()
print aa.b
Run Code Online (Sandbox Code Playgroud)
它打印:
<bound method classobj.b of <class __main__.a at 0x00B2DC00>>
Run Code Online (Sandbox Code Playgroud) from wtforms import Form, BooleanField, TextField, validators,PasswordField
class LoginForm(Form):
username = TextField('Username', [validators.Length(min=4, max=25)])
password = PasswordField('Password')
Run Code Online (Sandbox Code Playgroud)
当我在webapp(gae)上使用LoginForm时,如下所示:
def post(self):
form=LoginForm(self.request)
Run Code Online (Sandbox Code Playgroud)
但它显示错误:
Traceback (most recent call last):
File "D:\Program Files\Google\google_appengine\google\appengine\ext\webapp\__init__.py", line 513, in __call__
handler.post(*groups)
File "D:\zjm_code\forum_blog_gae\main.py", line 189, in post
form=LoginForm(self.request)
File "D:\zjm_code\forum_blog_gae\wtforms\form.py", line 161, in __call__
return type.__call__(cls, *args, **kwargs)
File "D:\zjm_code\forum_blog_gae\wtforms\form.py", line 214, in __init__
self.process(formdata, obj, **kwargs)
File "D:\zjm_code\forum_blog_gae\wtforms\form.py", line 85, in process
raise TypeError("formdata should be a multidict-type wrapper that supports the 'getlist' method")
TypeError: …
Run Code Online (Sandbox Code Playgroud) 鉴于代码:
a=['a','b','c','d']
b=a[::-1]
print b
c=zip(a,b)
print c
c.sort(key=lambda x:x[1])#
print c
Run Code Online (Sandbox Code Playgroud)
它打印:
['d', 'c', 'b', 'a']
[('a', 'd'), ('b', 'c'), ('c', 'b'), ('d', 'a')]
[('d', 'a'), ('c', 'b'), ('b', 'c'), ('a', 'd')]
Run Code Online (Sandbox Code Playgroud)
为什么[('a','d'),('b','c'),('c','b'),('d','a')]变为[('d') ,'a'),('c','b'),('b','c'),('a','d')]?
同样,给出:
c.sort(key=lambda x:3)#
print c
Run Code Online (Sandbox Code Playgroud)
它打印:
[('a', 'd'), ('b', 'c'), ('c', 'b'), ('d', 'a')]
Run Code Online (Sandbox Code Playgroud)
没有什么变化 - 为什么?
django项目中的许多目录包含一个__init__.py
,我认为它将用作某些东西的初始化.这在哪里__init__.py
使用?
这是我的代码:
var a='(1,2,3,4)'
a=a.slice(-1,1)
alert(a)
Run Code Online (Sandbox Code Playgroud)
我没有打印任何东西.
谢谢
name_iexact
关键字是我们可以传递给 django.model 中的过滤函数的参数。有人可以帮我了解一下吗?
Map.objects.filter(name__iexact=self.cleaned_data["name"]).count()
Run Code Online (Sandbox Code Playgroud) 这是我的代码:
f = open('text/a.log', 'wb')
f.write('hahaha')
f.close()
Run Code Online (Sandbox Code Playgroud)
并且在不存在时不创建新文件
这该怎么做 ,
谢谢
更新
class MyThread(threading.Thread):
def run(self):
f = open('a.log', 'w')
f.write('hahaha')
f.close()
Run Code Online (Sandbox Code Playgroud)
错误是:
Traceback (most recent call last):
File "D:\Python25\lib\threading.py", line 486, in __bootstrap_inner
self.run()
File "D:\zjm_code\helloworld\views.py", line 15, in run
f = open('a.log', 'w')
File "d:\Program Files\Google\google_appengine\google\appengine\tools\dev_appserver.py", line 1188, in __init__
raise IOError('invalid mode: %s' % mode)
IOError: invalid mode: w
Run Code Online (Sandbox Code Playgroud)