小编Cla*_*ani的帖子

如何扩展Sphinx中侧边栏toctree上的所有子部分

我想知道是否有办法扩展文件中包含的标题下的所有子部分index.rst

举个例子,它是这样的:

Section 1
Section 2
Section 3
Run Code Online (Sandbox Code Playgroud)

以下是我希望如何:

Section 1
  Subsection 1.1
  Subsection 1.2
  Subsection 1.3
Section 2
  Subsection 2.1
  Subsection 2.2
  Subsection 2.3
Section 3
  Subsection 3.1
  Subsection 3.2
  Subsection 3.3
Run Code Online (Sandbox Code Playgroud)

如果我点击第1部分,它会显示下面的内容,但是如果我点击第2部分,则隐藏第1部分的内容,只显示2.我想在每次进入索引页面时扩展所有2个部分.我试过加toctreemaxdepth,没有什么作品.

python documentation sidebar python-sphinx

35
推荐指数
1
解决办法
1867
查看次数

aiohttp中基于类的视图

aiohttp库中使用基于类的处理程序而不是函数的正确方法是什么?我习惯在Django中将处理程序编写为类,所以我想知道如何在aiohttp中正确地执行它?

python aiohttp python-3.5

7
推荐指数
1
解决办法
1867
查看次数

TypeError:不可排序的类型:Python 3中的tuple()<int()

以下代码用于订购扑克手。它在Python 2.7中可以很好地工作,但在Python 3中却不起作用。已经进行了哪些更改,使其产生TypeError:不可排序的类型:tuple()<int()?

def poker(hands):
    scores = [(i, score(hand.split())) for i, hand in enumerate(hands)]
    winner = sorted(scores , key=lambda x:x[1])[-1][0]
    return hands[winner]

def score(hand):
    ranks = '23456789TJQKA'
    rcounts = {ranks.find(r): ''.join(hand).count(r) for r, _ in hand}.items()
    score, ranks = zip(*sorted((cnt, rank) for rank, cnt in rcounts)[::-1])
    if len(score) == 5:
        if ranks[0:2] == (12, 3): #adjust if 5 high straight
            ranks = (3, 2, 1, 0, -1)
        straight = ranks[0] - ranks[4] == 4
        flush = len({suit for _, suit …
Run Code Online (Sandbox Code Playgroud)

python sorting python-3.x

4
推荐指数
1
解决办法
8872
查看次数

为什么在这个Rails方法中无法获救ActiveRecord :: StatementInvalid?

为什么我不能用以下方法拯救任何东西?

def get_things
  begin
    things= @member.things.where("id>?",params[:id])
  rescue ActiveRecord::StatementInvalid
    render( inline: "RESCUED ActiveRecord::StatementInvalid" )
    return
  rescue
    render( inline: "RESCUED something" )
    return
  end
  render( inline: "#{things.first.title}" )
end
Run Code Online (Sandbox Code Playgroud)

使用有效ID调用时,它可以工作:

$  curl -vd "id=3" http://localhost:3000/get_things
Run Code Online (Sandbox Code Playgroud)

但如果我错了一个,例如:

$  curl -vd "id=3,0" http://localhost:3000/get_things
$  curl -vd "id='3'" http://localhost:3000/get_things
Run Code Online (Sandbox Code Playgroud)

异常未获救:

< HTTP/1.1 500 Internal Server Error
<h1>
  ActiveRecord::StatementInvalid
    in ApplicationController#get_things
</h1>
<pre>PG::Error: ERROR:  invalid input syntax for integer: &quot;'3'&quot;
Run Code Online (Sandbox Code Playgroud)

仅在渲染发生在开始/救援块内时

def get_things
  begin
    things= @member.things.where("id>?",params[:id])
    render( inline: "#{things.first.title}" )
  rescue ActiveRecord::StatementInvalid
    render( inline: "RESCUED ActiveRecord::StatementInvalid" …
Run Code Online (Sandbox Code Playgroud)

activerecord ruby-on-rails exception rescue

2
推荐指数
1
解决办法
3149
查看次数

"捆绑更新"和"宝石更新"有什么区别?

我有一个Ruby on Rails应用程序,我正在使用Ruby Version Manager.我可以使用bundle update或更新宝石gem update吗?他们做同样的事吗?

ruby gem ruby-on-rails bundler rvm

2
推荐指数
1
解决办法
2515
查看次数