我不确定它是MongoEngine中的一个错误还是我错过了什么.我设置了以下模型:
class Features(EmbeddedDocument):
version = FloatField()
data = ListField(StringField)
class Article(Document):
vendor = ReferenceField(Vendor)
url = URLField()
author = StringField()
clean_content = StringField()
features = EmbeddedDocumentField(Features)
Run Code Online (Sandbox Code Playgroud)
当我测试我的模型时:
#add vendor
vendor = Vendor(name="techcrunch", config="vendor config")
vendor.save()
#create features
features = Features(version = 1.0)
features.data = ["5", "89"]
#add article
article = Article(vendor = vendor, url ="http://www.techcrunch.com",
author ="MG Siegler", clean_content = "Apple rocks!")
article.features = features
article.save()
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
TypeError: unbound method _validate() must be called with StringField instance as first argument …Run Code Online (Sandbox Code Playgroud) 我有:
val foo = Some(List(1, 2, 3)) -> Some("y")
Run Code Online (Sandbox Code Playgroud)
我想投射它:
foo match {
case (Some(x), Some(y)) => println(x + " " + y)
case _ => println("error")
Run Code Online (Sandbox Code Playgroud)
这适用于Some(List(1, 2, 3) -> Some("score"))但是失败Some(List(1, 2, 3) -> None,None -> Some("y")或者None -> None:
error: constructor cannot be instantiated to expected type;
found : Some[A]
required: None.type
error: not found: value ...
Run Code Online (Sandbox Code Playgroud)
这是为什么?
当然我可以使用,getOrElse()但看起来不那么优雅.
很多,卡斯滕
更新:
foo match {
case (x: Some[List[Int]], y: Some[Int]) …Run Code Online (Sandbox Code Playgroud) 我有它工作,但不能相信语法应该是疯了.我想做的就是将所有以第三个开头的参数放入一个数组中.
例如
script.sh foo bar value1 value2 value3
Run Code Online (Sandbox Code Playgroud)
应该给我一个包含value1,value2和value3的数组.该数组用于在新函数中提供参数:
./runpy /dsnormalize.py "${values[@]}"
Run Code Online (Sandbox Code Playgroud)
这有效:
args=( "$@" )
length=$((${#args[@]}-2))
values=(${args[@]:$length:2})
Run Code Online (Sandbox Code Playgroud)
请告诉我这不是正确的方法.我通常最终得到一个包含所有值的字符串.
bash如何处理字符串和整数?$ {}和$()之间的区别是什么?
谢谢你的帮助,卡斯滕