我正在制作一个像大表盘一样旋转的圆圈.目前,我在顶部有一个箭头,显示表盘朝向哪个方向.我希望它的行为有点像一个老式的旋转手机,这样当你的手指/光标向下时你可以旋转它,但它会(放慢)在你松开后慢慢地回到顶部.
这是我的对象的样子:

这是我的代码:
#!/usr/bin/kivy
import kivy
kivy.require('1.7.2')
import math
from random import random
from kivy.app import App
from kivy.uix.widget import Widget
from kivy.uix.gridlayout import GridLayout
from kivy.uix.anchorlayout import AnchorLayout
from kivy.uix.relativelayout import RelativeLayout
from kivy.graphics import Color, Ellipse, Rectangle
class MinimalApp(App):
title = 'My App'
def build(self):
root = RootLayout()
return(root)
class RootLayout(AnchorLayout):
pass
class Circley(RelativeLayout):
angle = 0
def on_touch_down(self, touch):
ud = touch.ud
ud['group'] = g = str(touch.uid)
return True
def on_touch_move(self, touch):
ud = touch.ud
# print(touch.x, …Run Code Online (Sandbox Code Playgroud) 在命令行上,这有效:
$ mongo
> show dbs
mydatabase 1.0GB
Run Code Online (Sandbox Code Playgroud)
但是,这不是:
$ python
>>> import pymongo
>>> connection = pymongo.MongoClient()
>>> connection.mydatabase.find()
Run Code Online (Sandbox Code Playgroud)
我在这里阅读文档:
http://api.mongodb.org/python/current/tutorial.html
但是不明白怎么做......
为什么我无法访问我的数据库?
有很多很好的getattr()函数用于解析嵌套的字典结构,例如:
我想做一个并行的setattr().基本上,给定:
cmd = 'f[0].a'
val = 'whatever'
x = {"a":"stuff"}
Run Code Online (Sandbox Code Playgroud)
我想生成一个我可以分配的功能:
x['f'][0]['a'] = val
Run Code Online (Sandbox Code Playgroud)
或多或少,这将以与以下相同的方式工作:
setattr(x,'f[0].a',val)
Run Code Online (Sandbox Code Playgroud)
产量:
>>> x
{"a":"stuff","f":[{"a":"whatever"}]}
Run Code Online (Sandbox Code Playgroud)
我现在叫它setByDot():
setByDot(x,'f[0].a',val)
Run Code Online (Sandbox Code Playgroud)
这样做的一个问题是,如果中间的密钥不存在,则需要检查并生成中间密钥(如果不存在) - 即,对于上述情况:
>>> x = {"a":"stuff"}
>>> x['f'][0]['a'] = val
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'f'
Run Code Online (Sandbox Code Playgroud)
所以,你首先必须做:
>>> x['f']=[{}]
>>> x
{'a': 'stuff', 'f': [{}]}
>>> x['f'][0]['a']=val
>>> x
{'a': 'stuff', 'f': [{'a': 'whatever'}]}
Run Code Online (Sandbox Code Playgroud)
另一个是当下一个项目是一个字符串时,键入当下一个项目是一个字符串时,键入不同,即:
>>> x = {"a":"stuff"}
>>> x['f']=['']
>>> x['f'][0]['a']=val
Traceback …Run Code Online (Sandbox Code Playgroud) 我正在将我的org-mode文件导出到LaTeX,并经常使用C-c .时间戳作为顶级标题作为滚动日记.
但是,当它导出为PDF时,<2014-04-25 Fri>看起来有点滑稽.是否存在将时间戳转换为某种格式化日期的常规设置,例如"2014年4月25日星期五"或其他一些常见的日期字符串格式?
我看了一下,明白有几种方法可以输入日期,但我想也必须有输出格式.我也看到,有一个出口时间戳设置在这里,
<:
Toggle inclusion of any time/date active/inactive stamps (org-export-with-timestamps).
Run Code Online (Sandbox Code Playgroud)
但目前还不清楚实施意味着什么.
我目前正在对一组我要并行化的变量进行合并.我的代码看起来像这样:
mergelist = [
('leftfile1', 'rightfile1', 'leftvarname1', 'outputname1'),
('leftfile1', 'rightfile1', 'leftvarname2', 'outputname2')
('leftfile2', 'rightfile2', 'leftvarname3', 'outputname3')
]
def merger(leftfile,rightfile,leftvarname,outvarname):
do_the_merge
for m in mergelist:
merger(*m)
Run Code Online (Sandbox Code Playgroud)
通常,为了加快长循环,我会用merge之类的东西替换合并列表中的for m.
from multiprocessing import Pool
p = Pool(8)
p.map(merger(m), mergelist)
p.close()
Run Code Online (Sandbox Code Playgroud)
但是因为我正在使用星形来解包元组,所以我不清楚如何正确映射它.我怎么得到的*m?
:t myfunctionofinterest
Run Code Online (Sandbox Code Playgroud)
对于我在库中使用的函数.
但是,当我在我的项目根目录中运行时
$ stack ghci
Run Code Online (Sandbox Code Playgroud)
我的Main.hs有:
import MyLib
Run Code Online (Sandbox Code Playgroud)
我的模块做了:
module MyLib {
bunchOfFunctions -- but not myfunctionofinterest
} where
import SomeDB.ModuleThatExposes -- myfunctionofinterest
myfunc :: IO ()
myfunc = do
myfunctionofinterest a b c -- place where I misuse myfunctionofinterest and could have used :t on it to see it had 3 args
Run Code Online (Sandbox Code Playgroud)
我不能:t在主要的myfunctionofinterest,因为它没有暴露,也没有Import MyLib.myfunctionofinterest明确的帮助,因为它是在导入中定义的东西.虽然我知道我可以暴露它然后检查它,:a编译,然后编辑lib再次隐藏它,有没有什么允许更快,更直接?
这似乎必须是一种常见的模式.当您需要在开发时检查库中使用的类型时,您会怎么做?
我正试图在jupyter中安装IHaskell,直接来自这里的说明.
我跑了以下.
sudo apt-get install -y python3-pip git libtinfo-dev libzmq3-dev libcairo2-dev libpango1.0-dev libmagic-dev libblas-dev liblapack-dev
git clone https://github.com/gibiansky/IHaskell
cd IHaskell
pip3 install -r requirements.txt
stack install gtk2hs-buildtools
# stack install --fast
# ihaskell install --stack
# jupyter labextension install ihaskell_jupyterlab
Run Code Online (Sandbox Code Playgroud)
我在上面的第5个命令上得到了这个错误,gtk2hs-buildtools一个:
(envname) me@machine:~/plc/IHaskell$ stack install gtk2hs-buildtools
Linking /home/me/.stack/setup-exe-cache/x86_64-linux/tmp-Cabal-simple_mPHDZzAJ_2.2.0.1_ghc-8.4.4 ...
/home/me/anaconda3/envs/envname/bin/../lib/gcc/x86_64-conda_cos6-linux-gnu/7.3.0/../../../../x86_64-conda_cos6-linux-gnu/bin/ld: cannot find -lgmp
collect2: error: ld returned 1 exit status
`x86_64-conda_cos6-linux-gnu-cc' failed in phase `Linker'. (Exit code: 1)
-- While building simple Setup.hs using:
/home/me/.stack/programs/x86_64-linux/ghc-8.4.4/bin/ghc -rtsopts …Run Code Online (Sandbox Code Playgroud) 这似乎是尽可能简单的:
import Data.Text as T
let x = "test"
T.putStrLn x
Run Code Online (Sandbox Code Playgroud)
但是我得到:
<interactive>:1:1: error:
Not in scope: ‘T.putStrLn’
No module named ‘T’ is imported.
Run Code Online (Sandbox Code Playgroud)
为什么不输入T?为什么Data.Text不导入为T?
我正在查看用于命名实体识别的 Huggingface 管道的文档,我不清楚这些结果如何用于实际的实体识别模型。
例如,给出文档中的示例:
>>> from transformers import pipeline
>>> nlp = pipeline("ner")
>>> sequence = "Hugging Face Inc. is a company based in New York City. Its headquarters are in DUMBO, therefore very"
... "close to the Manhattan Bridge which is visible from the window."
This outputs a list of all words that have been identified as an entity from the 9 classes defined above. Here is the expected results:
print(nlp(sequence))
[
{'word': 'Hu', 'score': 0.9995632767677307, 'entity': …Run Code Online (Sandbox Code Playgroud)