Skip to main content
 首页 » 编程设计

python之如何在 Python 中将 SASS 动态转换为 CSS

2025年05月04日10jiqing9006

我来自 PHP 背景,更具体地说是 Symfony2。 Symfony2 具有通过 Assetic 到 autmagically convert SASS file into CSS 的功能.

现在我正在使用 bottle 框架开发我的第一个 python 元素,我想知道是否存在一种类似的方法来即时生成 SASS 文件的 CSS。

在 python 世界中是否有与 Assetic 过滤器等效的东西?

在后台手动运行 compass 不是一种选择。我想使用 SASS,但整个过程对我的工作流程来说应该是非常的。

请您参考如下方法:

以不同的方式思考这个问题,我想我可以让我的 python 脚本运行 sass --watch source.sass:target.css 所以我跟进了 how to run bash commands in python .因此我的 __init_.py 现在包括:

bashCommand = "sass --watch ./css/main.sass:./css/main.css" 
import subprocess 
process = subprocess.Popen(bashCommand.split(), stdout=subprocess.PIPE) 

这导致 sass 文件自动转换为 css,而我不必担心整个 sass 转换方面。