操作系统可移植代码,用于引用模板文件

时间:2019-04-02 17:07:00

标签: go

下面是在Windows中运行的代码:

print_op = tf.print("tensors:", cut_points[0,0,:], output_stream=sys.stderr)
with tf.control_dependencies([print_op]):
    return tf.identity(cut_points)

在Linux中由于反斜杠(wd, err := os.Getwd() if err != nil { log.Fatal(err) } t, err := template.ParseFiles(wd + "\\src\\html\\index.html") )而失败

如何使此代码可跨操作系统移植?

1 个答案:

答案 0 :(得分:1)

通常使用filepath.Join是一种方法:

path := filepath.Join("separate", "me")

但是我认为filepath.FromSlash更具可读性:

path := filepath.FromSlash("separate/me")