小编fox*_*lue的帖子

有多个英雄在子树中共享相同的标记

我试图通过路线从一个屏幕导航到另一个屏幕.当我点击页面按钮移动到提供的路线时,我收到错误

I/flutter ( 8790): Another exception was thrown: There are multiple heroes that share the same tag within a subtree.
Run Code Online (Sandbox Code Playgroud)

这是代码:

路线:

 <String, WidgetBuilder>{
    '/first':(BuildContext context) =>NavigatorOne() ,
    '/second':(BuildContext context) =>NavigatorTwo(),
    '/third':(BuildContext context) =>NavigatorThree(),

  },

Navigator.of(context).pushNamed('/first');
Navigator.of(context).pushNamed('/second');
Navigator.of(context).pushNamed('/third');

class NavigatorOne extends StatefulWidget {
  @override
  _NavigatorOneState createState() =>  _NavigatorOneState();
}

class _NavigatorOneState extends State<NavigatorOne> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(

      appBar: AppBar(),
      body: Container(
      color: Colors.green,
      child: RaisedButton(child: Text(' one 1'),onPressed: (){
        Navigator.of(context).pushNamed('/second');
      },),
    ),
    ); 
  }
}
Run Code Online (Sandbox Code Playgroud)

而错误: …

flutter

50
推荐指数
5
解决办法
1万
查看次数

什么dtype用于pandas数据帧中的货币表示?

所以我有一个pandas dataframe对象,其中包含两列小数位的精度,如"133.04".没有带有3个或更多小数位的数字,只有两个.

我的尝试:十进制模块

我已经尝试使用Decimal模块,但是当我尝试像这样重新采样时

gr_by_price = df['price'].resample(timeframe, how='ohlc')
Run Code Online (Sandbox Code Playgroud)

我明白了

pandas.core.groupby.DataError: No numeric types to aggregate
Run Code Online (Sandbox Code Playgroud)

在此之前我检查dtype

print(type(df['price'][0]))
<class 'decimal.Decimal'>
Run Code Online (Sandbox Code Playgroud)

我是这个图书馆和资金处理的新手,也许Decimal不是这个的正确选择?我该怎么办?

如果我将此列投射到<class 'numpy.float64'>一切正常.

更新:现在我正在使用这种方法

d.Decimal("%0.2f" % float(d.Decimal("1.04")))
Decimal('1.04')
Run Code Online (Sandbox Code Playgroud)

这个问题

python python-3.x pandas

13
推荐指数
2
解决办法
3617
查看次数

Python argparse store_true 并将可选选项存储在一个参数中

我需要识别是否单独给出参数或带有可选字符串或两者都没有

parser.add_argument(???)
options = parser.parse_args()
Run Code Online (Sandbox Code Playgroud)

所以

./prog.py --arg
Run Code Online (Sandbox Code Playgroud)

应存储''到 options.arg 中,

./prog.py --arg=lol
Run Code Online (Sandbox Code Playgroud)

存储'lol'到 options.arg 中并且

./prog.py
Run Code Online (Sandbox Code Playgroud)

左 options.arg 为None

我现在有:

parser.add_argument("--arg", nargs="?",type=str,dest="arg")
Run Code Online (Sandbox Code Playgroud)

但是当我运行我的程序时./prog.py --argoptions.arg 仍然存在None。识别 --arg 的唯一方法是将其运行为./prog.py --arg=,这对我来说是个问题。

python optional-parameters argparse

3
推荐指数
1
解决办法
2227
查看次数

如何使用包含多个字符的分隔符将.txt解析为pandas df?

我有一个大型数据集,我想在python中使用pandas进行分析.它全部包含在.txt中,但分隔符是+++ $ +++.我怎么解析这个?

import pandas as pd
df = pd.read_csv('filename.txt', sep='+++$+++', header=None)
Run Code Online (Sandbox Code Playgroud)

这两行引出了这个错误:

sre_constants.error: nothing to repeat
Run Code Online (Sandbox Code Playgroud)

python regex separator pandas

3
推荐指数
1
解决办法
408
查看次数

如何在 Jira(Python) 中编辑/更新评论

我正在尝试使用 jira-python 编辑 jira 中的评论,但找不到任何内容。

我知道add_comment会添加评论,但我也想知道如何edit评论。

python jira python-jira jira-rest-api

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

如何测试Django CreateView?

我想练习在Django上进行测试,并且有一个要测试的CreateView。该视图允许我创建一个新帖子,我想检查它是否可以找到没有发布日期的帖子,但是首先我要测试具有发布日期的帖子,以习惯语法。这就是我所拥有的:

import datetime
from django.test import TestCase
from django.utils import timezone
from django.urls import reverse
from .models import Post, Comment

# Create your tests here.
class PostListViewTest(TestCase):

    def test_published_post(self):
        post = self.client.post('/post/compose/', {'author':"manualvarado22", 'title': "Super Important Test", 'content':"This is really important.", 'published_date':timezone.now()})
        response = self.client.get(reverse('blog:post_detail'))
        self.assertContains(response, "really important")
Run Code Online (Sandbox Code Playgroud)

但是我得到这个:

django.urls.exceptions.NoReverseMatch: Reverse for 'post_detail' with no 
arguments not found. 1 pattern(s) tried: ['post/(?P<pk>\\d+)/$']
Run Code Online (Sandbox Code Playgroud)

如何获得该新创建帖子的pk?

谢谢!

python django django-testing

3
推荐指数
1
解决办法
1661
查看次数

如何在函数映射/字典中模拟函数?

我正在尝试修补字典fun_1中的功能worker_functions,但我似乎很挣扎:

剪辑.py:
import sys

from worker_functions import (
    fun_1,
    fun_2,
    fun_3,
)

FUNCTION_MAP = {
    'run_1': fun_1,
    'run_2': fun_2,
    'run_3': fun_3,
}

def main():
    command = sys.argv[1]
    tag = sys.argv[2]
    action = FUNCTION_MAP[command]

    action(tag)
Run Code Online (Sandbox Code Playgroud)

我尝试过嘲笑cli.fun_1and cli.main.actioncli.action但这会导致失败。

测试_cli.py:
from mock import patch

from cli import main


def make_test_args(tup):
    sample_args = ['cli.py']
    sample_args.extend(tup)
    return sample_args


def test_fun_1_command():
    test_args = make_test_args(['run_1', 'fake_tag'])
    with patch('sys.argv', test_args),\
         patch('cli.fun_1') as mock_action:
        main()

        mock_action.assert_called_once()
Run Code Online (Sandbox Code Playgroud)

我似乎错过了什么吗?

python unit-testing mocking python-3.x

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

SQLSTATE[42S02]:未找到基表或视图:1146 表“prj_roocket.permissions”不存在

我创建一个迁移

Schema::create('roles', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('label')->nullable();
        $table->timestamps();
    });

    Schema::create('permissions', function (Blueprint $table) {
        $table->increments('id');
        $table->string('name');
        $table->string('label')->nullable();
        $table->timestamps();
    });

    Schema::create('permission_role', function (Blueprint $table) {
        $table->integer('role_id')->unsigned();
        $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');

        $table->integer('permission_id')->unsigned();
        $table->foreign('permission_id')->references('id')->on('permissions')->onDelete('cascade');

        $table->primary(['role_id' , 'permission_id']);
    });

    Schema::create('role_user', function (Blueprint $table) {
        $table->integer('role_id')->unsigned();
        $table->foreign('role_id')->references('id')->on('roles')->onDelete('cascade');

        $table->integer('user_id')->unsigned();
        $table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');

        $table->primary(['role_id' , 'user_id']);
    });
Run Code Online (Sandbox Code Playgroud)

我在 CMD 中写的任何内容php artisan migrate and composer dumpautoload and php artisan serve and...都会看到此错误。我也删除了数据库并创建了一个新数据库。

[Illuminate\Database\QueryException] SQLSTATE[42S02]:未找到基表或视图:1146 表“prj_roocket.permissions”不存在(SQL:select * from permissions

[PDOException] SQLSTATE[42S02]:未找到基表或视图:1146 表“prj_roocket.permissions”不存在

php laravel

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