简体   繁体   English

使用python mako时如何返回其他类型的数据

[英]when use python mako how to return other type data

from mako.template import Template

t=Template("${x}").render(x=[1,2,3])
print(type(t))   # <class 'str'>
print(t)         # [1, 2, 3]

t=Template("${x}").render(x=5)
print(type(t))  #<class 'str'>
print(t)        # 5

Why return is not a list or int, what do I want to get为什么 return 不是 list 或 int,我想得到什么

can i use ?,But I was disappointed我可以用吗?,但我很失望

t=Template("${int(x)}").render(x=5)
print(type(t))   #<class 'str'>
print(t)         #5

You can type cast to the data type you want, using您可以将类型转换为所需的数据类型,使用

t = int(Template("${int(x)}").render(x=5))

or或者

t = [Template("${int(x)}").render(x=5)]

Thank you for your advice, but it's not what I want.谢谢你的建议,但这不是我想要的。 The type of data I passed in is unknown我传入的数据类型未知

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM