我正在寻找一个以JSON格式格式在python任意嵌套的dict /数组上运行的函数,并返回一个字符串列表,将其包含的所有变量名称键入到无限深度.所以,如果对象是......
x = {
'a': 'meow',
'b': {
'c': 'asd'
},
'd': [
{
"e": "stuff",
"f": 1
},
{
"e": "more stuff",
"f": 2
}
]
}
Run Code Online (Sandbox Code Playgroud)
mylist = f(x) 会回来......
>>> mylist
['a', 'b', 'b.c', 'd[0].e', 'd[0].f', 'd[1].e', 'd[1].f']
Run Code Online (Sandbox Code Playgroud) 这适用于mongo终端
$ mongo datas
> db.mydb.update({},{$set : {'ids.my_key':''}}, {multi:true})
Run Code Online (Sandbox Code Playgroud)
但是从命令行进行评估时失败了.
mongo datas --eval "db.mydb.update({},{$set : {'ids.my_key':''}}, {multi:true})"
MongoDB shell version: 2.4.5
connecting to: datas
Thu Dec 12 12:35:24.063 JavaScript execution failed: SyntaxError: Unexpected token :
Run Code Online (Sandbox Code Playgroud)
我认为这与报价相关,但未能使其发挥作用.
我想在文件名给出的文件中一次读取和处理 1024 个字节。我不明白如何正确构建外循环,尤其是适应缓冲区包含少于 1024 字节的最终步幅
我尝试过的:
fs, _ := os.Open(filename)
defer fs.Close()
n := 1024 // 1kb
buff := make([]byte, n)
for {
buff = make([]byte, n) // is this initialized correctly?
n1, err := fs.Read(buff)
if err != nil {
if err == io.EOF {
break
}
fmt.Println(err)
break
}
fmt.Println("read n1 bytes...", n1)
fmt.Println(buff)
}
Run Code Online (Sandbox Code Playgroud)
我看过以下资源:
我理解没有"位置"参数,因为所有函数只接受一个变量并返回一个函数来操作剩余的参数,但这就是我想要做的意思:
从一些函数开始,我用来格式化带有前置项,分隔符和结束项的列表.
Prelude> formatList start end sep xs = start ++ (intercalate . separator ( map show xs )) ++ end
Run Code Online (Sandbox Code Playgroud)
像这样工作:
Prelude Data.List> formatList "(" ")" "," [1..10]
"(1,2,3,4,5,6,7,8,9,10)"
Run Code Online (Sandbox Code Playgroud)
很酷,同样的想法可以用于xml标签:
Prelude Data.List> formatList "<meow>" "</meow>" "" [1..10]
"<meow>12345678910</meow>"
Run Code Online (Sandbox Code Playgroud)
本着重用函数和简洁性的精神,让我们也做到这一点,我们不必通过创建一个函数来生成打开和关闭单词"tag",从而输入meow标记的冗余部分.
Prelude Data.List> tagger tag item = "<" ++ tag ++ ">" ++ item ++ "</" ++ tag ++ ">"
Prelude Data.List> tagger "div" "contents"
"<div>contents</div>"
Run Code Online (Sandbox Code Playgroud)
所以现在制作一些标签制作器,它将返回一个开始和结束我可以为我的formatList函数创建第二个参数:
Prelude Data.List> tagMaker tag = ("<" ++ tag ++ ">", "</" ++ tag ++ …Run Code Online (Sandbox Code Playgroud) 我对另类的前奏感兴趣。我了解有很多选择:
我了解其中很多简单的问题是文本,而另一种问题是类似head错误的函数,而您可能更喜欢它们更安全。
但是,当我尝试使用这些替代方法时head,hmm中的行为似乎完全破坏了该功能,并且对我而言似乎不是一种改进。这里有些例子:
Prelude> head [1]
1
Prelude> head []
*** Exception: Prelude.head: empty list
Run Code Online (Sandbox Code Playgroud)
Foundation> head [1]
<interactive>:6:6: error:
• Couldn't match expected type ‘NonEmpty c’
with actual type ‘[Integer]’
• In the first argument of ‘head’, namely ‘[1]’
In the expression: head [1]
In an equation for ‘it’: it = head [1]
• Relevant bindings include
it :: foundation-0.0.21:Foundation.Collection.Element.Element c
(bound at <interactive>:6:1)
Foundation> head []
<interactive>:7:6: error:
• Couldn't …Run Code Online (Sandbox Code Playgroud) 我的Haskell文件顶部有以下内容:
{-# LANGUAGE DeriveGeneric, OverloadedStrings, DefaultSignatures, TypeOperators, FlexibleContexts, RecordWildCards, FlexibleInstances, ExtendedDefaultRules #-}
module Main where
import qualified Data.Map as Map
import qualified Data.Set as Set
import Data.Text (Text)
import Data.DateTime
import Data.Aeson
newtype Price = Price Float deriving Generic
Run Code Online (Sandbox Code Playgroud)
但是,当我运行时:
$ stack ghci
...
Prelude> :l myfile.hs
[1 of 1] Compiling Main ( myfile.hs, interpreted )
myfile.hs:13:38: error:
Not in scope: type constructor or class ‘Generic’
|
13 | newtype Price = Price Float deriving Generic
| ^^^^^^^
Failed, no …Run Code Online (Sandbox Code Playgroud) 在尝试调试另一个问题时,我安装了一个似乎与我其他安装的一些软件包冲突的软件包。
\n\n我跑了
\n\n$ stack install regex-pcre-text\nregex-pcre-builtin-0.94.4.8.8.35: configure\nregex-tdfa-1.2.3.1: download\nregex-pcre-builtin-0.94.4.8.8.35: build\nregex-tdfa-1.2.3.1: configure\nregex-tdfa-1.2.3.1: build\nregex-pcre-builtin-0.94.4.8.8.35: copy/register\nregex-tdfa-1.2.3.1: copy/register\nregex-tdfa-text-1.0.0.3: download \nregex-tdfa-text-1.0.0.3: configure \nregex-tdfa-text-1.0.0.3: build \nregex-tdfa-text-1.0.0.3: copy/register\nregex-pcre-text-0.94.0.1: download \nregex-pcre-text-0.94.0.1: configure \nregex-pcre-text-0.94.0.1: build \nregex-pcre-text-0.94.0.1: copy/register\nCompleted 4 action(s). \nRun Code Online (Sandbox Code Playgroud)\n\n我不能再简单地导入
\n\nText.Regex.PCRE\nRun Code Online (Sandbox Code Playgroud)\n\n当我尝试时,我现在看到:
\n\n$ stack ghci\nPrelude> :set -XOverloadedStrings\nPrelude> import Text.Regex.PCRE\nRun Code Online (Sandbox Code Playgroud)\n\n产量
\n\n<no location info>: error:\n Ambiguous module name \xe2\x80\x98Text.Regex.PCRE\xe2\x80\x99:\n it was found in multiple packages:\n regex-pcre-0.94.4 regex-pcre-builtin-0.94.4.8.8.35\nRun Code Online (Sandbox Code Playgroud)\n\n我想将我的安装恢复到早期状态,以便我的计算机上Text.Regex.PCRE未经限定导入的代码继续像以前一样工作。
然而,看起来堆栈没有明确的卸载:
\n\n$ stack uninstall regex-pcre-text\n\nError: stack does …Run Code Online (Sandbox Code Playgroud) 我在 Ubuntu 中通过 snap 安装了 docker。它工作正常,直到我重新启动。由于重新启动,它不会保持启动状态。
所以我们手动启动守护进程:
$ sudo snap start docker
Started.
Run Code Online (Sandbox Code Playgroud)
凉爽的。看起来开始给我。
$ docker run hello-world
docker: Cannot connect to the Docker daemon at unix:///var/run/docker.sock. Is the docker daemon running?.
See 'docker run --help'.
Run Code Online (Sandbox Code Playgroud)
不。不,它不是。
这是怎么回事,我该如何解决?
我希望能够手动启动它,并在登录时自动启动。
我目前有一个查询,其工作方式如下:
select AVG(t2 - t1) as delay,
percentile_cont(0.25) within group (order by (t2 - t1)) as q25,
percentile_cont(0.5) within group (order by (t2 - t1)) as median,
percentile_cont(0.75) within group (order by (t2 - t1)) as q75,
p.bool1,
p.cat1
from people p
group by p.bool1, p.cat1
order by p.cat1,p.bool1
Run Code Online (Sandbox Code Playgroud)
但是,我在 postgres 函数聚合页面上阅读: https://www.postgresql.org/docs/9.4/functions-aggregate.html
我应该能够指定多个分位数:
percentile_cont(fractions) WITHIN GROUP (ORDER BY sort_expression) double precision[] double precision or interval array of sort expression's type multiple continuous percentile: returns an array of results matching …Run Code Online (Sandbox Code Playgroud) 在 R 中,我可以像这样移动阿拉斯加和夏威夷: https://www.storybench.org/how-to-shift-alaska-and-hawaii-below-the-lower-48-for-your-interactive-choropleth-地图/
我可以在 cartopy 中这样做: 在 Cartopy 地图中显示阿拉斯加和夏威夷
如何使用 geopandas 做类似的事情?
这就是我所拥有的...
import requests
import geopandas
import numpy as np
np.random.seed(5)
URL = 'https://github.com/kjhealy/us-county/raw/master/data/geojson/gz_2010_us_040_00_500k.json'
us_json = requests.get(URL).json()
# save to disk as fname then load from file
usa = geopandas.read_file(fname)
usa["value"] = np.random.uniform(low=0,high=100, size=52)
usa.sort_values("NAME", inplace=True)
usa
Run Code Online (Sandbox Code Playgroud)
现在绘制它:
usa.plot(column='value', cmap='Reds', scheme='quantiles', k=7, legend=True)
Run Code Online (Sandbox Code Playgroud)
仅限大陆:
usa.plot(column='value', cmap='Reds', scheme='quantiles', k=7, legend=True)
Run Code Online (Sandbox Code Playgroud)
我应该怎么做才能添加阿拉斯加和夏威夷的子图?
haskell ×4
python ×2
choropleth ×1
dictionary ×1
docker ×1
geopandas ×1
ghci ×1
gis ×1
go ×1
javascript ×1
json ×1
mongodb ×1
nested-lists ×1
plot ×1
postgresql ×1
pragma ×1
quantile ×1
ubuntu-19.04 ×1