你如何比较Fish中的两个字符串(就像"abc" == "def"在其他语言中一样)?
到目前为止,我已经使用了一个组合contains(事实证明contains "" $a只有返回,0如果$a是空字符串,虽然在所有情况下似乎都不适用于我)和switch(使用a case "what_i_want_to_match"和a case '*').但是,这些方法似乎都不是特别正确.
unittest.TestCase有一个assertCountEqual方法(assertItemsEqual在Python 2中,可以说是一个更好的名称),它比较两个迭代并检查它们是否包含相同数量的相同对象,而不考虑它们的顺序.
pytest提供类似的东西吗?所有明显的替代方案(例如调用set(x),sorted(x)或Counter(list(x))文档中提到的每一方)都不起作用,因为我正在比较的是字典列表,而且字典不可清除.
我想定义一个泛型类型ExcludeCart<T>,它基本上是T用给定键(在我的情况下cart)删除的.所以,例如,ExcludeCart<{foo: number, bar: string, cart: number}>将是{foo: number, bar: string}.有没有办法在TypeScript中执行此操作?
这就是我想要这样做的原因,以防我咆哮错误的树:我正在将现有的JavaScript代码库转换为TypeScript,它包含一个名为的装饰器函数cartify,它接受一个React组件类Inner并返回另一个组件类Wrapper.
Inner应该采取cart道具,以及零或多个其他道具.Wrapper接受一个cartClient道具(用于生成cart要传递到的道具Inner)和任何Inner接受的道具,除了 cart.
换句话说,一旦我弄清楚如何定义ExcludeCart,我想用它来做:
function cartify<P extends {cart: any}>(Inner: ComponentClass<P>) : ComponentClass<ExcludeCart<P> & {cartClient: any}>
Run Code Online (Sandbox Code Playgroud) generics decorator typescript reactjs higher-order-components
我有一个Django 1.7迁移,看起来像这样:
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
def units_to_m2m(apps, schema_editor):
Interval = apps.get_model("myapp", "Interval")
IntervalUnit = apps.get_model("myapp", "IntervalUnit")
for interval in Interval.objects.all():
IntervalUnit(
interval=interval,
unit=interval.unit,
base_date=interval.base_date
).save()
class Migration(migrations.Migration):
dependencies = [
('otherapp', '0007_auto_20150310_1400'),
('myapp', '0009_auto_20150316_1608'),
]
operations = [
migrations.CreateModel(
name='IntervalUnit',
# ...
),
# ...
migrations.AddField(
model_name='interval',
name='units',
field=models.ManyToManyField(to='otherapp.Unit', through='myapp.IntervalUnit'),
preserve_default=True,
),
migrations.RunPython(units_to_m2m),
migrations.RemoveField(
model_name='interval',
name='unit',
),
migrations.RemoveField(
model_name='interval',
name='base_date',
),
]
Run Code Online (Sandbox Code Playgroud)
当我跑步时manage.py migrate,它移植得很好.manage.py test但是,当我运行时,它会尝试创建测试数据库,然后在迁移过程中失败并出现以下错误: …
virtualfish指令的文档,为了让鱼提示显示当前virtualenv你应该更新全局fish_prompt函数并保存它(funced fish_prompt和funcsave fish_prompt).我没有发现这种方法特别优雅,因为我希望我的所有自定义config.fish.因此,我的问题是,通过仅进行更改来显示当前virtualenv名称的最简单方法是什么?fish promptconfig.fish
因此,如果foobar是当前环境的名称,如何显示它:
(foobar) gedefar@Jakobs-MacBook-Pro ~/w/pyprototypes`
Run Code Online (Sandbox Code Playgroud) 我在使用Fabric将文件上传到服务器时遇到了一些问题.我得到以下输出:
Fatal error: Low level socket error connecting to host ssh.example.com: No route to host
Aborting.
Run Code Online (Sandbox Code Playgroud)
奇怪的是,当我手动连接ssh(相同的主机字符串,我从fabfile复制粘贴以确保)时,它按预期完美地工作.我也可以使用scp手动将文件复制到同一位置.
我的Fabfile中的违规行是这个,如果它有帮助:
put('media.tgz','/home/private/media.tgz')
Run Code Online (Sandbox Code Playgroud)
此外,我使用@hosts()装饰器连接到我的fabfile的其他主机(这个特殊的方法上传静态媒体,这是从与应用程序本身不同的地方提供).
python ×3
fish ×2
decorator ×1
django ×1
fabric ×1
generics ×1
pytest ×1
reactjs ×1
ssh ×1
typescript ×1
unit-testing ×1
virtualenv ×1
virtualfish ×1