Equivalent of Python string.format in Go?

前端 未结 6 1927
我在风中等你
我在风中等你 2020-12-02 17:18

In Python, you can do this:

\"File {file} had error {error}\".format(file=myfile, error=err)

or this:

\"File %(file)s had e         


        
6条回答
  •  攒了一身酷
    2020-12-02 18:02

    Alas, there's no built-in function in Go for string interpolation with named parameters (yet). But you are not the only one suffering out there :) Some packages should exist, for example: https://github.com/imkira/go-interpol . Or, if feeling adventurous, you could write such a helper yourself, as the concept is actually quite simple.

    Cheers, Dennis

提交回复
热议问题