我可以使用“parse”模块中的预定义数据类型来通过“cfparse”解析列表参数吗?
我在 PyCharm 2017.2 中使用行为 1.2.6.dev0。.特征是:
Scenario Outline:
Given Drone flies <directions> for <distances> meters
Then it will be <distance> meters from launchpad
Examples:
| directions | distances | distance |
|North, West | 3, 4 | 5 |
Run Code Online (Sandbox Code Playgroud)
步骤文件是
from behave import *
use_step_matcher("cfparse")
@given("Drone flies {directions+} for {distances:n+} meters")
def step_impl(context, directions, distances):
pass
@then("it will be {distance:n} meters from launchpad")
def step_impl(context, distance):
pass
Run Code Online (Sandbox Code Playgroud)
这里的 {directions+} 应该是一个字符串列表,其中“+”表示 1..* 基数。“n”是“解析模块”中预定义的数字类型。(来自https://pythonhosted.org/behave/tutorial.html 和https://jenisys.github.io/behave.example/datatype/builtin_types.html)
我收到错误:... 文件“.../python3.6/site-packages/parse.py”,第 614 行,在 …
假设一个函数循环以产生数字结果.如果达到最大迭代或满足"最优"条件,则停止循环.在任何一种情况下,都会输出当前循环的值.获得这个结果和停止原因的功能方法是什么?
为了说明,这是我在https://www.cs.kent.ac.uk/people/staff/dat/miranda/whyfp90.pdf的 4.1中的"Square Roots"示例的Scala实现.
object SquareRootAlg {
def next(a: Double)(x: Double): Double = (x + a/x)/2
def repeat[A](f: A=>A, a: A): Stream[A] = a #:: repeat(f, f(a))
def loopConditional[A](stop: (A, A) => Boolean)(s: => Stream[A] ): A = s match {
case a #:: t if t.isEmpty => a
case a #:: t => if (stop(a, t.head)) t.head else loopConditional(stop)(t)}
}
Run Code Online (Sandbox Code Playgroud)
例如,找到4的平方根:
import SquareRootAlg._
val cond = (a: Double, b: Double) => (a-b).abs < 0.01
val alg = loopConditional(cond) …Run Code Online (Sandbox Code Playgroud)