当我想阅读逻辑编程时,我总是偶然发现两种"主要"方式来做到这一点:
我现在感兴趣的是:两者之间的主要技术差异是什么?它们在方法和实现方面是非常相似的,还是采用完全不同的逻辑编程方法?他们来自哪些数学分支,理论基础是什么?
我试图在我的flask应用程序中保存缓存字典.
据我所知,应该使用Application Context,特别是flask.g对象.
建立:
import flask as f
app = f.Flask(__name__)
Run Code Online (Sandbox Code Playgroud)
如果我这样做:
with app.app_context():
f.g.foo = "bar"
print f.g.foo
Run Code Online (Sandbox Code Playgroud)
它打印bar.
继续以下内容:
with app.app_context():
print f.g.foo
AttributeError: '_AppCtxGlobals' object has no attribute 'foo'
Run Code Online (Sandbox Code Playgroud)
我不明白,文档根本没有帮助.如果我正确阅读它们,应该保留状态.
我的另一个想法是简单地使用模块范围的变量:
cache = {}
def some_function():
cache['foo'] = "bar"
Run Code Online (Sandbox Code Playgroud)
但似乎每次请求都会重置这些内容.
怎么做到这一点?
编辑: Flask 10.1
file { 'leiningen':
path => '/home/vagrant/bin/lein',
ensure => 'file',
mode => 'a+x',
source => 'https://raw.github.com/technomancy/leiningen/stable/bin/lein',
}
Run Code Online (Sandbox Code Playgroud)
是我的想法,但木偶不知道http://.有什么关于puppet://我错过的吗?
或者如果没有,有没有办法以声明方式首先获取文件然后将其用作本地源?
在我生成的数组中,我有一个图像读入numpy中有相当多的像素.
我计算了一个包含256个值的查找表.现在我想做以下事情:
for i in image.rows:
for j in image.cols:
mapped_image[i,j] = lut[image[i,j]]
Run Code Online (Sandbox Code Playgroud)
是的,这基本上就像一个人.
唯一的问题是:我想做到高效并在python中调用该循环将让我等待几秒钟才能完成.
我知道numpy.vectorize(),它只是一个调用相同python代码的便捷函数.
我想改变用Better Rainbow圆括号着色的括号的颜色.
颜色指定如下:
let g:rbpt_colorpairs = [
\ ['brown', 'RoyalBlue3'],
\ ['Darkblue', 'SeaGreen3'],
\ ['darkgray', 'DarkOrchid3'],
\ ['darkgreen', 'firebrick3'],
\ ['darkcyan', 'RoyalBlue3'],
\ ['darkred', 'SeaGreen3'],
\ ['darkmagenta', 'DarkOrchid3'],
…
\ ]
Run Code Online (Sandbox Code Playgroud)
更改插件中颜色的功能如下:
func! rainbow_parentheses#toggle()
if !exists('s:active')
cal rainbow_parentheses#load(0)
endif
let afunc = exists('s:active') && s:active ? 'clear' : 'activate'
cal call('rainbow_parentheses#'.afunc, [])
endfunc
Run Code Online (Sandbox Code Playgroud)
由于我使用的是Solarized,我想要特定的十六进制颜色,所以我得到了这个:
let g:rbpt_colorpairs = [
\ ['yellow', '#b58900'],
\ ['orange', '#cb4b16'],
\ ['red', '#dc322f'],
\ ['magenta', '#d33682'],
\ ['violet', '#6c71c4'],
\ ['blue', '#268bd2'],
\ ['cyan', …Run Code Online (Sandbox Code Playgroud) 如何访问之类的东西sin,cos或PI在纯Clojure的方法吗?
例如,如果我想编写一个纯库,我不能使用像(.PI Math)(Java)或(.?PI?js/Math)(JS)这样的东西.
我整理了以下一堆很棒的东西:
if !exists("g:AsciidocAutoSave")
let g:AsciidocAutoSave = 0
endif
fun! AsciidocRefresh()
if g:AsciidocAutoSave == 1
execute 'write'
execute 'silent !asciidoc -b html5 -a icons "%"'
endif
endf
fun! AsciidocFocusLost()
augroup asciidocFocusLost
autocmd FocusLost <buffer> call AsciidocRefresh()
augroup END
endfun
augroup asciidocFileType
autocmd FileType asciidoc :call AsciidocFocusLost()
augroup END
Run Code Online (Sandbox Code Playgroud)
唯一的问题是:每次 vim 在asciidoc文件中失去焦点时,它都会保存两次。
当我输入:autocmd asciidocFileType命令行时,它显示:
---Auto-Commands---
asciidocFileType FileType
asciidoc :call AsciidocFocusLost()
:call AsciidocFocusLost()
Run Code Online (Sandbox Code Playgroud)
:autocmd asciidocFocusLost与相同AsciidocRefresh()。
为什么要重复?
我想这样做:
(-> string
(str/split "\s")
(modification-1)
(modification-2)
…
(modification-n
(str/join "\n"))
Run Code Online (Sandbox Code Playgroud)
但不,拆分[s regex]和加入需要[seperator coll].
这种疯狂有没有明显的原因(读:这背后的设计决定是什么)?
这不是关于如何使用argparse,而是关于如何在程序中使用解析的选项。
在函数的选项中检查选项/使用值的好方法是什么?
一些想法:
if-clause每一个东西依赖于一个选项的时间(全局变量?)必须有一些我监督的技术,这对于具有大量选项的大型程序似乎不可行,尤其是当程序的不同部分有多个文件时。
当我不使用main函数中的某些导入(应该很容易检测到)时,GHC会剥离相应的绑定吗?
例:
import Text.Parsec (parse)
import My.Testframework (test)
main = parse …
tests = test …
Run Code Online (Sandbox Code Playgroud)
会My.Testframework在可执行文件中链接吗?
对于循环函数直到谓词成立有
until :: (a -> Bool) -> (a -> a) -> a -> a
Run Code Online (Sandbox Code Playgroud)
然而,一旦谓词具有以下形式,这就不够了
Monad m => (a -> m b)
Run Code Online (Sandbox Code Playgroud)
我发现的唯一方法是通过显式递归,例如从句柄读取直到EOF达到:
(_, (Just stdout), _, _) <- createProcess (proc "task" (args fl)){ std_out = CreatePipe }
let readH :: IO [Either String Task] -> IO [Either String Task]
readH l = do eof <- hIsEOF stdout
if eof
then l
else do line <- hGetLine stdout
l' <- l
readH.return $ (eitherDecodeStrict' line) : l'
out …Run Code Online (Sandbox Code Playgroud) 我听说这句话Python太慢了,无法在浏览器中使用.
我认为Javascript在这方面只是优势,因为公司喜欢Google快速(快速)需要它的公司,因为他们需要它来生存,但我可能是错的.
设计的方式Python和JS设计是否会影响它们在浏览器中的表现?