完成Python教程.我创建了一个不执行预期的简单脚本(myFirstFunction).我期望一行输出只是两个变量相乘:
apples = raw_input("How many apples do you have?")
oranges = raw_input("How many oranges do you have?")
def myFirstFunction(apples, oranges):
total_fruit = apples * oranges
print total_fruit
Run Code Online (Sandbox Code Playgroud)
该脚本确实按预期要求输入,但不打印结果?
myName-MacBook:pythonhard me$ python ex19b.py
How many apples do you have?2
How many oranges do you have?2
myNames-MacBook:pythonhard me$
Run Code Online (Sandbox Code Playgroud)
为什么不打印4?
我正在通过Learn Python the Hard Way教程.我已经回过头几个练习,试图真正了解Zed的(作者)OOP示例游戏(练习43).
谨慎,我想我明白了 - 什么类和对象是什么.我在理论上至少理解鱼和鲑鱼,汽车和本田等之间的区别.
我知道我们使用类和对象(而不是只按需编写函数)以重用代码(对吧?).
我的思绪链条现在很微妙,但我不能休息,睡觉或感觉满足,直到我真正点击这一点.
游戏中有许多场景(场景是游戏中的一个类).例如中央走廊,大桥,Escape Pod.
除了场景之外,游戏还使用引擎和地图(对象).我完全不了解这些组件如何使游戏运行.
在脚本的最后,开始游戏的是代码块:
a_map = Map('central_corridor')
a_game = Engine(a_map)
a_game.play()
Run Code Online (Sandbox Code Playgroud)
具体问题:
这是游戏:
from sys import exit
from random import randint
class Scene(object):
def enter(self):
print "This scene is not yet configured. Subclass it and implement enter()."
class Engine(object):
def __init__(self, scene_map):
print "Engine __init__ has scene_map", scene_map
self.scene_map = scene_map
def play(self):
current_scene = self.scene_map.opening_scene()
print "Play's first scene", current_scene
while True:
print "\n--------"
next_scene_name = …Run Code Online (Sandbox Code Playgroud) 我有一个countifs功能:
COUNTIFS(DB!$C:$C,"<>"&"",DB!$Q:$Q,OR(DB!$Q:$Q="-",DB!$Q:$Q>Summary!B7),DB!$N:$N,"<="&B7)
Run Code Online (Sandbox Code Playgroud)
问题必须是嵌套的OR语句.
这是一个新的条件,我之前使用的其他东西不准确.
我需要选择以下数据:DB!C:C不是空白; DB!Q:Q等于" - "OR大于B7; DB!N:N小于或等于B7.
在countifs语句中嵌套此OR语句的正确方法是什么?
我现在只是在Chrome的控制台中.我创建了这个变量:
url = window.location.href
Run Code Online (Sandbox Code Playgroud)
这使:
url" http://www.example.com/trips/dest/australia-and-south-pacific/cntry/fiji/ "
现在我尝试了这个:
if (url.indexOf('australia-and-south-pacific') > 0) {return 'foo';}
Run Code Online (Sandbox Code Playgroud)
返回的是:
SyntaxError: Illegal return statement
Run Code Online (Sandbox Code Playgroud)
我希望控制台能够返回'foo'.
为什么会这样?我注意到收到此错误后,给它几秒钟,然后出现一个新错误:
Uncaught TypeError: Cannot read property 'hide' of undefined
Run Code Online (Sandbox Code Playgroud)
如果这有助于诊断?
我将一个csv读入R,现在我有一个数据列表.
head(data)
Date Open High Low Close Volume
1 31-Dec-14 223.09 225.68 222.25 222.41 2402097
2 30-Dec-14 223.99 225.65 221.40 222.23 2903242
3 29-Dec-14 226.90 227.91 224.02 225.71 2811828
4 26-Dec-14 221.51 228.50 221.50 227.82 3327016
5 24-Dec-14 219.77 222.50 219.25 222.26 1333518
6 23-Dec-14 223.81 224.32 219.52 220.97 4513321
tail(data)
Date Open High Low Close Volume
499 9-Jan-13 34.01 34.19 33.40 33.64 697979
500 8-Jan-13 34.50 34.50 33.11 33.68 1283985
501 7-Jan-13 34.80 34.80 33.90 34.34 441909
502 4-Jan-13 …Run Code Online (Sandbox Code Playgroud) 我设置了一个cookie:
<script>
document.cookie="cid1={{utm_campaign}}; path=/;"
</script>
Run Code Online (Sandbox Code Playgroud)
{{}}是一个宏,是Google-Tag-Manager语法,请忽略它.
每当有人使用如下标记登陆example.com时,都会触发上述脚本:example.com/?utm_medium=test&utm_source=bla&utm_campaign=foo.我测试了它,当然,当我使用这些参数登陆主页时,cookie已经设置好了.
但是访问者可以移动到子域dogs.example.com.当我在控制台中查看时,cookie cid1不再存在.
除了将路径设置为"/"以便cookie交叉到子域外,创建cookie时是否可以更改设置?
我想使用应用程序脚本选择单元格 C29:Z50 作为变量。我宁愿不必创建命名范围(但如果需要,我可以)。
我的目标是在可以使用内置功能的颜色之外创建一些自定义格式。因此,如果单元格 B27 = "Transactions" 则将 C29:Z50 格式化为数字,否则将 Z29:Z50 格式化为美元货币。
所以我不需要单元格的值,只需要单元格组作为一个变量,如果逻辑我可以应用它。
我在这里阅读文档。
获取数据范围()
返回与存在数据的维度相对应的范围。这在功能上等同于创建一个由 A1 和 (Range.getLastColumn(), Range.getLastRow()) 界定的范围。
文档中的示例抓取了整个选项卡,但我只想要有问题的工作表的一个子集。
我试过:
var currency_range = ss.getDataRange(C29, Z50); //"Reference Error. "C29" is not defined."
var currency_range = ss.getDataRange(C29:Z50); // "Missing ) argument list"
Run Code Online (Sandbox Code Playgroud)
如何“获取”单元格范围,以便以后可以根据条件编辑它们的格式?
一些数据:
x <- structure(list(X. = c("4,084", "4,084", "4,084", "4,084", "4,084"
), ADR = c("1,099.69", "68.66", "232.72", "195.66", "98"), hotel_id = c("2,313,076",
"583,666", "1,251,372", "1,545,890", "298,160"), city_id = c("9,395",
"17,193", "5,085", "16,808", "8,584"), star_rating = c(5, 2,
3, 4, 4), accommodation_type_name = c("Hotel", "Bungalow", "Hotel",
"Hotel", "Hotel"), chain_hotel = c("chain", "non-chain", "non-chain",
"non-chain", "non-chain"), booking_date = c("10/5/2016", "12/4/2016",
"11/6/2016", "10/22/2016", "12/11/2016"), checkin_date = c("10/27/2016",
"12/9/2016", "11/18/2016", "11/3/2016", "12/11/2016"), checkout_date = c("10/30/2016",
"12/12/2016", "11/20/2016", "11/4/2016", "12/12/2016"), city = c("A",
"B", "C", "D", …Run Code Online (Sandbox Code Playgroud) 我有一些 json 数据,其中包含属性“字符”,它看起来像这样:
select json_data['characters'] from latest_snapshot_events
Run Code Online (Sandbox Code Playgroud)
返回: [{"CHAR_STARS":1,"CHAR_A1_LVL":1,"ITEM_POWER":60,"CHAR_A3_LVL":1,"CHAR_TIER":1,"ITEM":10,"shards":0,"CHAR_TPIECES":0,"CHAR_A5_LVL":0,"CHAR_A2_LVL":1,"CHAR_A4_LVL":1,"ITEM_CATEGORY":"Character","ITEM_LEVEL":3},{"CHAR_STARS":1,"CHAR_A1_LVL":1,"ITEM_POWER":50,"CHAR_A3_LVL":1,"CHAR_TIER":1,"ITEM":39,"shards":0,"CHAR_TPIECES":0,"CHAR_A5_LVL":0,"CHAR_A2_LVL":1,"CHAR_A4_LVL":1,"ITEM_CATEGORY":"Character","ITEM_LEVEL":2},{"CHAR_STARS":1,"CHAR_A1_LVL":1,"ITEM_POWER":80,"CHAR_A3_LVL":1,"CHAR_TIER":1,"ITEM":6801450488388220,"shards":0,"CHAR_TPIECES":0,"CHAR_A5_LVL":1,"CHAR_A2_LVL":1,"CHAR_A4_LVL":1,"ITEM_CATEGORY":"Character","ITEM_LEVEL":4},{"CHAR_STARS":1,"CHAR_A1_LVL":1,"ITEM_POWER":85,"CHAR_A3_LVL":1,"CHAR_TIER":1,"ITEM":8355588830097610,"shards":0,"CHAR_TPIECES":5,"CHAR_A5_LVL":0,"CHAR_A2_LVL":1,"CHAR_A4_LVL":1,"ITEM_CATEGORY":"Character","ITEM_LEVEL":4}]
这是在单行上返回的。我希望数组中的每个项目都占一行。
我发现了一些 SO 帖子和其他博客建议我使用unnest(). 我已经尝试了几次,但无法返回结果。例如,这是来自 presto 的文档。底部盖板展开,作为蜂巢横向视图爆炸的替代品:
SELECT student, score
FROM tests
CROSS JOIN UNNEST(scores) AS t (score);
Run Code Online (Sandbox Code Playgroud)
所以我尝试将其应用到我的表中:
characters as (
select
jdata.characters
from latest_snapshot_events
cross join unnest(json_data) as t(jdata)
)
select * from characters;
Run Code Online (Sandbox Code Playgroud)
其中json_data,latest_snapshot_events 中包含属性“characters”的字段,该属性是一个类似于上面所示的数组。
这会返回一个错误:
[Simba]AthenaJDBC AWS Athena 客户端抛出错误。SYNTAX_ERROR:第 69:12 行:列别名列表有 1 个条目,但“t”有 2 列可用
如何取消嵌套/分解latest_snapshot_events.json_data['characters']到多行?
一个简单的应用程序:
#
# This is a Shiny web application. You can run the application by clicking
# the 'Run App' button above.
#
# Find out more about building applications with Shiny here:
#
# http://shiny.rstudio.com/
#
library(shiny)
# Define UI for application that draws a histogram
ui <- fluidPage(
# Application title
titlePanel("blah"),
# Sidebar with a slider input for number of bins
sidebarLayout(
sidebarPanel(),
# Show a plot of the generated distribution
mainPanel(
DT::DTOutput('ex_df')
)
)
)
# …Run Code Online (Sandbox Code Playgroud)