小编アレッ*_*ックス的帖子

Play Framework 2的脚手架

是否有适用于Scala的Play Framework 2的脚手架生成器实用程序,如Ruby on Rails?我找到了一些关于这方面的话题,但没有弄清楚哪一个最受欢迎,或者哪个是最标准的?

你的意见?

更新:我的意思是脚手架用于生成控制器,视图,模型或其中任何一个.

scala playframework-2.0

11
推荐指数
1
解决办法
2205
查看次数

在ElementTree中检查XML元素是否包含子元素

我以这种方式检索XML文档:

import xml.etree.ElementTree as ET

root = ET.parse(urllib2.urlopen(url))
for child in root.findall("item"):
  a1 = child[0].text # ok
  a2 = child[1].text # ok
  a3 = child[2].text # ok
  a4 = child[3].text # BOOM
  # ...
Run Code Online (Sandbox Code Playgroud)

XML看起来像这样:

<item>
  <a1>value1</a1>
  <a2>value2</a2>
  <a3>value3</a3>
  <a4>
    <a11>value222</a11>
    <a22>value22</a22>
  </a4>
</item>
Run Code Online (Sandbox Code Playgroud)

我如何检查a4(在这种特殊情况下,但它可能是任何其他元素)是否有孩子?

python xml children elementtree

11
推荐指数
2
解决办法
2万
查看次数

无法登录系统用户postgres

我使用brew在mac上安装了postgresql.在安装过程中我没有被问及postgresql的密码.现在我需要创建一个用户而不能:

Alexs-MacBook-Air:mydir alex$ su - postgres
Password:
su: Sorry
Run Code Online (Sandbox Code Playgroud)

无论我使用什么密码(包括空),都是错的.重置它的最简单方法是什么?

postgresql macos postgresql-9.2

10
推荐指数
3
解决办法
2万
查看次数

sbt 0.12.4 - 有x个功能警告; 重新运行-feature以获取详细信息

我收到一个错误there were 15 feature warning(s); re-run with -feature for details:

$ /usr/local/sbt/bin/sbt
[info] Loading project definition from /home/alex/Documents/projects/my_app123/project
[info] Set current project to sbt-android (in build file:/home/alex/Documents/projects/my_app123/)

> compile -feature
[error] Expected end of input.
[error] compile -feature
[error]        ^

> sbt-version
[info] 0.12.4

> compile 
[warn] Credentials file /home/alex/.ivy2/.credentials does not exist
[info] Compiling 20 Scala sources to /home/alex/Documents/projects/my_app123/target/scala-2.10/sbt-0.12/classes...
[error] there were 15 feature warning(s); re-run with -feature for details
[error] one error found
[error] (compile:compile) Compilation …
Run Code Online (Sandbox Code Playgroud)

scala sbt scalac

10
推荐指数
2
解决办法
3077
查看次数

字符串插值:f或s

我想知道,这两者之间有什么区别:

val a = 123
println(f"hello1 $a") // 1                         
println(s"hello1 $a") // 2
Run Code Online (Sandbox Code Playgroud)

scala scala-2.10

9
推荐指数
2
解决办法
5496
查看次数

没有ClassTag可用于MyClass.this.T的抽象类型

这很好用

class MyClass[T<: Actor: ClassTag] extends Actor {
  //....
}
Run Code Online (Sandbox Code Playgroud)

但这不是由于错误 No ClassTag available for MyClass.this.T

class MyClass extends Actor {
  type T<: Actor
  //...
}
Run Code Online (Sandbox Code Playgroud)

即使执行以下操作:

class MyClass extends Actor {
  type T<: Actor: ClassTag //this doesn't even compile
  //...
}
Run Code Online (Sandbox Code Playgroud)

我如何使用摘要type并摆脱错误?

scala type-erasure type-parameter type-members

9
推荐指数
1
解决办法
2879
查看次数

找不到setup.py中的File.open(自述文件)

setup.py我发送到pip的Python包中的文件:

#!/usr/bin/env python

from distutils.core import setup

setup(
    #......
    long_description=open('README.md').read(),
    #....
)
Run Code Online (Sandbox Code Playgroud)

该文件README.md存在.将断点放入setup.py并在本地执行时,它会很好地读取文件.但是,当我从pip(pip install my_lib)安装它时,它会在安装过程中抛出一个异常:

File "/private/var/folders/ty/0nvksfhn29z_cjb6md2t3x8c0000gn/T/pip_build_alex/my_app123/setup.py", line 14, in <module>
        long_description=open('README.md').read(),
    IOError: [Errno 2] No such file or directory: 'README.md'
    Complete output from command python setup.py egg_info:
Run Code Online (Sandbox Code Playgroud)

更新:

我刚刚从pip下载了我的库,解压缩并发现文件README,LICENSE,MANIFEST不在其中.他们在gitignore也是因为他们存在于github.

python

9
推荐指数
1
解决办法
2276
查看次数

无法使用"写入"将通用案例类转换为json

我有一个类,我希望能够转换为json:

case class Page[T](items: Seq[T], pageIndex: Int, pageSize: Int, totalCount: Long)

object Page {

  implicit val jsonWriter: Writes[Page[_]] = Json.writes[Page[_]]
}
Run Code Online (Sandbox Code Playgroud)

错误是 No apply function found matching unapply parameters

json scala playframework playframework-2.2

8
推荐指数
3
解决办法
4390
查看次数

按编号(索引)引用列

我想使用列的索引(数字)执行选择.我试过了:

select 1 from "user"
select '1' from "user"
Run Code Online (Sandbox Code Playgroud)

但他们不按我的意愿行事.

sql postgresql select postgresql-9.2

8
推荐指数
2
解决办法
7628
查看次数

函数签名上缺少生命周期说明符[E0106]

我很困惑这个简单代码(Playground)的错误:

fn main() {
    let a = fn1("test123");
}

fn fn1(a1: &str) -> &str {
    let a = fn2();
    a
}

fn fn2() -> &str {
    "12345abc"
}
Run Code Online (Sandbox Code Playgroud)

这些是:

error[E0106]: missing lifetime specifier
  --> <anon>:10:13
   |
10 | fn fn2() -> &str {
   |             ^ expected lifetime parameter
   |
   = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
   = help: consider giving it a 'static lifetime …
Run Code Online (Sandbox Code Playgroud)

rust

8
推荐指数
1
解决办法
6614
查看次数