这是一个配置文件,我使用 PyYAML 从中更改了一些值,然后我编写了一些配置,但它会更改我的格式,这让我感到困惑。
$ results.yaml
nas:
mount_dir: '/nvr'
mount_dirs: ['/mount/data0', '/mount/data1', '/mount/data2']
# yaml.py
import yaml.py
conf = open("results.conf", "r")
results = yaml.load(conf)
conf.close()
result['nas']['mount_dirs'][0]= "haha"
with open('/home/zonion/speedio/speedio.conf', 'w') as conf:
yaml.dump(speedio, conf, default_flow_style=False)
conf.close()
Run Code Online (Sandbox Code Playgroud)
但它改变了我的格式,我该怎么办?
# cat results.conf
nas:
mount_dir: /nvr
mount_dirs:
- haha
- /mount/data1
- /mount/data2
Run Code Online (Sandbox Code Playgroud) 我似乎有这个答案并使用@OneOfOne 答案。 你如何让 Golang 程序打印它刚刚调用的错误的行号?
但是有一些问题。
func FancyHandleError(err error) (b bool) {
if err != nil {
pc, fn, line, _ := runtime.Caller(1)
log.Printf("[error] in %s[%s:%d] %v", runtime.FuncForPC(pc).Name(), fn, line, err)
b = true
}
return
}
func main(){
FancyHandleError?funcA())
}
func funcA()error{
err := funcB()
return err
}
func funcB()error{
err := funcC()
return err
}
func funcC()error{
err := errors.New("deep errors!!") //I want to get the location in here!!!!!!!!!!!!!!!!!!!!!!
return err
}
Run Code Online (Sandbox Code Playgroud)
它将打印“ [error] in main.main[/root/temp/error.go:23] ”,这是在函数 main …