我有这两个班:
class Person(db.Model):
person_name = db.StringProperty(required = True)
#gender = db.StringProperty(required = True)
nacionality = db.StringProperty(required = True)
marital_status = db.StringProperty(required = True)
profession = db.StringProperty(required = True)
SSN = db.IntegerProperty(required = True)
driver_license = db.IntegerProperty(required = True)
address = db.PostalAddressProperty(required = True)
class ContractingParty(db.Model):
person = db.ReferenceProperty(Person, required=True, collection_name="party_to_contracts")
contract = db.ReferenceProperty(Contract, required=True)
condition = db.StringProperty()
Run Code Online (Sandbox Code Playgroud)
我想将ContractingParty实体的查询传递给我的jinja2模板.然后使用a for loop,我想从Person实体获取我真正想要的数据.缔约方查询正在传递给jinja2(如果我测试它,我可以看到这样的东西:)[<main.ContractingParty object at 0x0492D770>].但是for loop波纹管没有工作,没有信息for loop显示在我的布朗瑟中.我该怎么办呢?
{% for party in parties %}
<li> {{party.person.person_name}} …Run Code Online (Sandbox Code Playgroud) 在处理程序函数内部我正试图存储并获取名为"theses"的数组数组的值:
var fact_list = [ ["Kennedy Inauguration", "politics", "tZwnNdFNkNklYc3pVUzZINUV4eUtWVWFSVEf"], ["Pericles’ Funeral Oration", "politics", "sdgrewaNkNklYc3pVUzZINUV4eUtW345ufaZ"], ["The Pleasure of Books", "culture", "1234rFszdgrfYc3pVUzZINUV4eU43usacd"], ["I Am The First Accused (Nelson Mandela)", "law", "34rsgadOsidjSZIswjadi95uydnfklsdks"] ];
function submit(e){
Logger.log("running submit(e)");
var numberOfItems = e.parameter.checkbox_total;
var itemsSelected = [];
// for each item, if it is checked / selected, add it to itemsSelected
for(var i = 0; i < numberOfItems; i++){
if(e.parameter['checkbox_isChecked_'+i] == 'true'){
itemsSelected.push(e.parameter['checkbox_value_'+i]);
}
}
var app = UiApp.getActiveApplication();
Logger.log("itemsSelected = " + itemsSelected);
ScriptProperties.setProperties({'theses': …Run Code Online (Sandbox Code Playgroud) Python新手建立他的第一个webapp的旅程(应用程序链接:http://contractpy.appspot.com/ - 它只是一个实验性的应用程序).
根据stackoverflow用户的建议,我开始使用模板系统:Jinja2(我使用的是Python 2.6),但是现在我遇到了这个错误:
2012-06-17 11:44:39 Running command: "['C:\\Python26\\pythonw.exe', 'C:\\Program Files (x86)\\Google\\google_appengine\\dev_appserver.py', '--admin_console_server=', '--port=8084', 'C:\\Users\\CG\\Documents\\udacity\\contract']"
Warning: You are using a Python runtime (2.6) that is older than the production runtime environment (2.7). Your application may be dependent on Python behaviors that have changed and may not work correctly when deployed to production.
WARNING 2012-06-17 14:44:41,993 datastore_file_stub.py:518] Could not read datastore data from c:\users\cg\appdata\local\temp\dev_appserver.datastore
WARNING 2012-06-17 14:44:42,005 dev_appserver.py:3401] Could not initialize images API; you are …Run Code Online (Sandbox Code Playgroud) 我有这个 Google Apps 脚本,可以向我在电子表格中选择的人发送一封包含请求的电子邮件:
function sendRequestEmail() {
var data = SpreadsheetApp.openById(SPREADSHEET);
if(!employee_ID) {
employee_ID = getCurrentRow();
if (employee_ID == 1) {
var employee_ID = Browser.inputBox("Você precisa selecionar um assistido?", "Choose a row or type its number here:", Browser.Buttons.OK_CANCEL);
}
}
// Fetch variable names
// they are column names in the spreadsheet
var sheet = data.getSheets()[0];
var columns = getRowAsArray(sheet, 1);
Logger.log("Processing columns =" + columns);
var employeeData = getRowAsArray(sheet, employee_ID);
Logger.log("Processing employeeData = " + employeeData);
// Assume first …Run Code Online (Sandbox Code Playgroud) 我是一个编程新手,在Python乘法方面有困难.我有这样的代码:
def getPriceDiscount():
price = int(input())
if price > 3000:
priceDiscount = price * 0.6
return priceDiscount
else:
return price
Run Code Online (Sandbox Code Playgroud)
但是当我执行它并输入一个像87.94这样的十进制数字的输入时,我收到以下错误:
ValueError: invalid literal for int() with base 10: '87.94'
Run Code Online (Sandbox Code Playgroud)
是不是该int()方法能够将字符串'87 .94'转换为允许我将其乘以0.6的数字?我该怎么做才能执行转换?
我正在使用Python 3.2.2.
我编写了下面的代码,我期待的是,当第一个循环结束并且不返回False时,流程将跟随第二个while循环.但是,流会跳过第二个while循环,只返回True.这是为什么?如何解决这个问题,使第一个while循环后的流程进入第二个while循环?
square = [[1,2,3,4],[4,3,1,4],[3,1,2,4],[2,4,4,3]]
# this is an auxiliary function
def getSum(lis):
sum = 0
for e in lis:
sum = sum + e
return sum
# here is where the problem is
def check_game(square):
standardSum = getSum(range(1, len(square)+1))
while square: #this is the first while loop
row = square.pop()
print row, 'row', 'sum of row=', getSum(row)
if standardSum != getSum(row):
return False
m = 0
while m < len(square): # the second while loop, which the flow skips
n …Run Code Online (Sandbox Code Playgroud) 1)当我执行此查询时:
contract_record = Contract(book_number = 42, initial_page = 420, final_page = 442)
contract_record.put()
contract_key = contract_record.key()
contract = db.GqlQuery("SELECT * FROM Contract WHERE __key__ = KEY('Contract', '$[contract_key]')").get()
Run Code Online (Sandbox Code Playgroud)
结果是无.为什么?
2)如何通过密钥进行此查询,而不是key_id?(像这样:
contract_id = contract_record.key().id()
contract = db.GqlQuery("SELECT * FROM Contract WHERE __key__ = KEY('Contract', '$[contract_id]')").get()
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助!
我在javascript中有一个返回两个值的函数:
function today_date() {
var t = new Date();
var day = t.getUTCDay();
var dayW = t.getDay(); // Day of de week (0-6).
return [day, dayW];
}
Run Code Online (Sandbox Code Playgroud)
当我调用这个函数(在另一个函数中)时,我只有一个这样的值.
function print_anything() {
console.log("Today is the " + today_date() + " of the month.");
}
Run Code Online (Sandbox Code Playgroud)
我知道这是一个非常基本和新手的问题.但是我该怎么做?
有没有办法通过Apps脚本在电子表格单元格中插入"显示单元格按钮以显示列表",即使用Data>>Data Validation电子表格菜单插入下拉列表(无需编程)?我需要在单元格中显示下拉列表(而不是在Uiapp中).
我知道如果你是一名代码大师,这似乎很愚蠢.但如果你回答它,你就会像编码器的超自然境界中的代码菩萨一样.这应该是一个笑话.
所以,我写了这段代码:
def media():
n = 0
soma = 0
while True:
print("Type a number")
num = input()
print type(num)
if num is int:
soma = soma + num
n = n + 1
print "soma =", soma, " num = ", num, " n = ", n
media = soma/n
print media
else:
break
media()
Run Code Online (Sandbox Code Playgroud)
当我运行代码时,我得到这样的东西:

我的问题是:为什么条件if num is int:不满足?
我的目标是使条件"如果用户键入ENTER,然后中断".
提前致谢.
python ×6
javascript ×2
jinja2 ×2
control-flow ×1
datastore ×1
gql ×1
if-statement ×1
math ×1
templates ×1
utf-8 ×1
while-loop ×1