python - 将 python bool 值转换为 javascript bool 值的更简洁的方法是什么?

标签 python

我想将 python bool 值转换为 JS 的 bool 值。这就是我正在使用的:

store = dict(vat=True)

if store['vat']:
    store.update({'vat': 'true'})
else:
    store.update({'vat': 'false'})

是否有更简洁的方法来替换此代码段?

最佳答案

>>> store['vat'] = json.dumps(store['vat'])
>>> store
{'vat': 'true'}

关于python - 将 python bool 值转换为 javascript bool 值的更简洁的方法是什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7805994/

相关文章:

python - 如何编写一个同时也是客户端的扭曲服务器?

python - "Pivot"将 Pandas DataFrame 转换为 3D numpy 数组

python - 使用 python 增量解析大型维基百科转储 XML 文件

python - 如何将具有多个模块的 pygame 应用程序转换为 .exe

python - django-haystack 空间搜索要求?

python - 为什么我用 matplotlib.imshow 绘制的 matplotlib 2D 直方图/热图与我的轴不匹配?

python - render_to_response 或 redirect 更改了 Django 1.8 中的模板元素

python - sklearn标签编码器: TypeError : '<' not supported between instances of 'int' and 'str'

python - 从属性包装方法返回修改后的文档字符串

python - 使用 Tensor Flow 对 MNIST 手写数字进行 CNN 训练的振荡精度