Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/279.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
coffeescript中类似python的字符串插值_Python_String_Coffeescript_String Interpolation_Language Comparisons - Fatal编程技术网

coffeescript中类似python的字符串插值

coffeescript中类似python的字符串插值,python,string,coffeescript,string-interpolation,language-comparisons,Python,String,Coffeescript,String Interpolation,Language Comparisons,我有这样一个错误的名称空间 errorMessages= error404Find: "Hosts not found" error404FindByHost: "Host - #{hostName} - not found" error400: "No host" 主机名应分配给null,并在如下函数中覆盖: this.hostName = 'smth' 或者我可以在python中使用类似的东西: errorMessages= {'error404Find': "Hosts

我有这样一个错误的名称空间

errorMessages=
  error404Find: "Hosts not found"
  error404FindByHost: "Host - #{hostName} - not found"
  error400: "No host"
主机名应分配给null,并在如下函数中覆盖:

this.hostName = 'smth'
或者我可以在python中使用类似的东西:

errorMessages=
  {'error404Find': "Hosts not found"
  'error404FindByHost': "Host - {hostName} - not found"
  'error400': "No host"}
errorMessages['error404FindByHost'].format(hostName='smth')

您可以将所有这些条目设置为函数,然后使用参数对其应用字典:

errorMessages=
  error404Find:-> "Hosts not found"
  error404FindByHost:-> "Host - #{@hostName} - not found"
  error400:-> "No host"

alert errorMessages["error404FindByHost"].apply hostName:"host1"