小编ind*_*iel的帖子

如何使用python以编程方式获取GCP Bearer令牌

gcloud auth print-access-token给我一个Bearer令牌,以后可以使用;但是,这是一个shell命令。如何通过Google Cloud Python API以编程方式获取一个?

我看到了使用oauth2client先前示例,但现在已弃用。如何使用google.authoauthlib做到这一点oauth2client

python google-cloud-platform google-iam

10
推荐指数
4
解决办法
3486
查看次数

Clojure Koan因子函数实现

我正在学习clojure并经历了clojure-koan练习.其中一个练习是关于实现阶乘功能.我在玩的时候注意到:

我的递归实现似乎适用于大数:

(defn factorial-1 [n]
   (loop [n n f 1]
      (if (= n 1)
          f
          (recur (dec n) (* f n)))))
Run Code Online (Sandbox Code Playgroud)

(factorial-1 1000N)在REPL中调用会产生一个数字:402387260077093773...

但是,当我尝试以下懒惰序列方法时:

(defn factorial-2 [n]
   (reduce * 1 (range 1 (inc n))))
Run Code Online (Sandbox Code Playgroud)

调用(factorial-2 1000N)REPL会产生错误:

ArithmeticException integer overflow  clojure.lang.Numbers.throwIntOverflow (Numbers.java:1388)
Run Code Online (Sandbox Code Playgroud)

为什么看似懒惰的序列方法会导致整数溢出错误?

recursion clojure

5
推荐指数
2
解决办法
145
查看次数