我在线获得了一个函数来帮助我完成当前的项目,它在某些行上有分号.我想知道为什么?是打破这个功能吗?
def containsAny(self, strings=[]):
alphabet = 'abcdefghijklmnopqrstuvwxyz0123456789'
for string in strings:
for char in string:
if char in alphabet: return 1;
return 0;
Run Code Online (Sandbox Code Playgroud)
我上网的功能很少修改:
for string in strings:
for char in string:
if char in alphabet: return 1;
Run Code Online (Sandbox Code Playgroud)
这是^说以下?
if char in alphabet:
return 1
break
Run Code Online (Sandbox Code Playgroud) 我想使用字典将值插入表中,我该怎么做?
import sqlite3
db = sqlite3.connect('local.db')
cur = db.cursor()
cur.execute('DROP TABLE IF EXISTS Media')
cur.execute('''CREATE TABLE IF NOT EXISTS Media(
id INTEGER PRIMARY KEY, title TEXT,
type TEXT, genre TEXT,
onchapter INTEGER, chapters INTEGER,
status TEXT
)''')
values = {'title':'jack', 'type':None, 'genre':'Action', 'onchapter':None,'chapters':6,'status':'Ongoing'}
#What would I Replace x with to allow a
#dictionary to connect to the values?
cur.execute('INSERT INTO Media VALUES (NULL, x)'), values)
cur.execute('SELECT * FROM Media')
meida = cur.fetchone()
print meida
Run Code Online (Sandbox Code Playgroud) 在Django模板语言中,是否使用带有for循环的else子句?我依赖我可以在for循环之前使用if检查,但这会重复.
python for-else
list = []
for i in list:
print i
else:
print 'list is empty'
Run Code Online (Sandbox Code Playgroud)
Django模板 - 其他(我猜)
<h1>{{ game.title}}</h1>
<table>
<tr>
{% for platform in game.platform_set.all %}
<td>{{ platform.system }} -- ${{ platform.price}}</td>
{% else %}
<td>No Platforms</td>
{% endfor %}
</tr>
</table>
<a href="{% url 'video_games:profile' game.id %}"></a>
Run Code Online (Sandbox Code Playgroud) 我试图通过使用该winfo_geometry()
功能找到我的窗口的大小,但它最终返回1x1+0+0
我也尝试过,winfo_height, winfo_width
但我一直在努力1
from tkinter import *
root=Tk()
root.geometry('400x600')
print (root.winfo_width())
print (root.winfo_height())
print (root.winfo_geometry())
root.mainloop()
Run Code Online (Sandbox Code Playgroud) 有没有办法复制变量,这样当变量'a'的值发生变化时,它会将自身复制到变量'b'?
例
a='hello'
b=a #.copy() or a function that will make a copy
a='bye'
# Is there a way to make
# 'b' equal 'a' without
# doing 'b=a'
print a
print b
Run Code Online (Sandbox Code Playgroud)
我在使用Tkinter库时遇到问题,我有一个已存储在列表中的checkbutton,我正在尝试获取它所拥有的变量.
但是需要大约5行代码才能到达变量.
我尽可能简化了代码,但仍无法将其置于中心位置.我相信我缺乏经验CSS
并不能让我看到非常简单的东西.
如果有人也知道一些css的好资源,这将是伟大的.我已阅读过许多CSS
书籍的部分,但都有非常基本的内容并涵盖了相同的内容.
CSS标记:
/* MAIN ––––––––––––––––––––– */
html {
/* overflow-y:scroll; */
}
body {
/* margin:0; */
/* position:relative; */
}
/* Form ––––––––––––––––––––– */
#form {
margin:0 auto;
width: 300px;
height: 200px;
display: inline-block;
border: 2px solid black;
}
Run Code Online (Sandbox Code Playgroud)
的index.html
<html>
<body>
<form id='form'></form>
</body>
</hml>
Run Code Online (Sandbox Code Playgroud) 我试图在等待5秒后删除文本框内的文本,但是程序不会运行并且会在其他所有内容上休眠.还有一种方法让我只是让我的文本框睡眠,所以我可以在文本被冻结时运行其他代码吗?
from time import time, sleep
from Tkinter import *
def empty_textbox():
textbox.insert(END, 'This is a test')
sleep(5)
textbox.delete("1.0", END)
root = Tk()
frame = Frame(root, width=300, height=100)
textbox = Text(frame)
frame.pack_propagate(0)
frame.pack()
textbox.pack()
empty_textbox()
root.mainloop()
Run Code Online (Sandbox Code Playgroud) 我在所有浏览器上重定向网页时遇到问题。大约一年前,我为客户创建了一个自定义页面SHOPIFY
,现在重定向功能不再有效。
我最初正在使用document.location.href = "/cart"
并且一切正常。但是我今天接到他的电话,说页面不会再重定向到他的IPhone
.
我将其更改为window.top.location.href
,这在除 safari 之外的大多数浏览器中修复了它。我知道在所有浏览器上工作的最佳方式是document
版本。但这似乎已经过时了今年。
setTimeout(function(){ document.location.href = '/cart';},1000);
Run Code Online (Sandbox Code Playgroud)
检查浏览器的用户代理,如果它是 safari,我们可以做一个不同的定制版本的重定向,只是还没有找到如何在新的 safari 上做到这一点。
@stanislav 似乎从这个链接有同样的问题,我怀疑我们会开始看到有这个问题的人数在增加。
为什么 window.location.href= 不使用 Safari 转发到页面?
感谢大家的意见和建议,希望早日得到解决。
我在表中有很多列,并希望SELECT * FROM Table
除了一列(例如:位置),而不必列出我想要使用的所有列.
SELECT * EXCEPT id FROM Table
???
我试图使用executemany函数从一行中的所有行中获取一些WHERE约束
import sqlite3
con = sqlite3.connect('test.db')
cur = con.cursor()
cur.execute('CREATE TABLE IF NOT EXISTS Genre (id INTEGER PRIMARY KEY, genre TEXT NOT NULL)')
values = [
(None, 'action'),
(None, 'adventure'),
(None, 'comedy'),
]
cur.executemany('INSERT INTO Genre VALUES(?, ?)', values)
ids=[1,2]
cur.executemany('SELECT * FROM Genre WHERE id=?', ids)
rows = cur.fetchall()
print rows
Run Code Online (Sandbox Code Playgroud)
cur.executemany('SELECT * FROM Genre WHERE id=?', ids)
sqlite3.ProgrammingError: You cannot execute SELECT statements in executemany()
Run Code Online (Sandbox Code Playgroud) python ×7
sqlite ×3
select ×2
tkinter ×2
break ×1
centering ×1
copy ×1
css ×1
dictionary ×1
django ×1
elapsedtime ×1
executemany ×1
function ×1
geometry ×1
if-statement ×1
insert ×1
javascript ×1
margin ×1
parameters ×1
python-3.x ×1
redirect ×1
safari ×1
size ×1
sleep ×1
sql ×1
time ×1
variables ×1