gpt4 book ai didi

python - Webassets - 排除 bundle 中的文件

转载 作者:行者123 更新时间:2023-12-01 05:53:36 27 4
gpt4 key购买 nike

我有一个目录,想要像 Ant 一样排除一些文件,这对于 webassets 是否可行?

或者如果bundle可以接受列表或元组,但情况似乎并非如此?

最佳答案

Bundle 构造函数签名如下所示(来自 the source at github ):

def __init__(self, *contents, **options):

这意味着内容可以指定为一系列位置参数,如the example in the documentation :

Bundle('common/inheritance.js', 'portal/js/common.js',
'portal/js/plot.js', 'portal/js/ticker.js',
filters='jsmin',
output='gen/packed.js')

但这也意味着你可以使用Python的能力unpack argument lists 。从该页面:

The reverse situation occurs when the arguments are already in a list or tuple but need to be unpacked for a function call requiring separate positional arguments. For instance, the built-in range() function expects separate start and stop arguments. If they are not available separately, write the function call with the *-operator to unpack the arguments out of a list or tuple

因此您可以轻松地将上面的示例编写为:

files = ['common/inheritance.js', 'portal/js/common.js', 
'portal/js/plot.js', 'portal/js/ticker.js']
Bundle(*files, filters='jsmin', output='gen/packed.js')

当然,您可以在捆绑之前根据自己的喜好对列表进行过滤/切片/切 block 。

关于python - Webassets - 排除 bundle 中的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13406301/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com