小编R. *_*uke的帖子

你可以调用gofmt来格式化你编写的Go代码中编写的文件吗?

我正在编写输出其他Go代码的Go代码.

我想知道是否有办法调用gofmt工具来格式化我写完的代码中编写的代码.

我在gofmt上找到的文档,例如官方文档,都涉及如何从命令行使用gofmt,但我想从Go代码本身调用它.

例:

func WriteToFile(content string) {
    file, err := os.Create("../output/myFile.go")
    if err != nil {
        log.Fatal("Cannot create file", err)
    }
    defer file.Close()
    fmt.Fprint(file, content)
    //Insert code to call gofmt to automatically format myFile.go here
}
Run Code Online (Sandbox Code Playgroud)

提前感谢您的时间和智慧.

go gofmt

3
推荐指数
1
解决办法
473
查看次数

Kivy:从 python 代码更改屏幕

我正在组装一个 Kivy 应用程序,但在解决如何在 python 代码中任意选择的点更改屏幕时遇到了一些问题。

在下面的例子中,我想知道如何通过执行一个函数我的文件来从Screen2回切换到。Screen1main.py

这是我的main.py

# -*- coding: utf-8 -*-

from kivy.app import App
from kivy.uix.screenmanager import ScreenManager, Screen, NoTransition
from kivy.properties import ObjectProperty
from functools import partial

import random
import time

class ScreenOne(Screen):
    pass

class ScreenTwo(Screen):

    def __init__(self,**kwargs):
        super(ScreenTwo, self).__init__(**kwargs)
        self.displayScreenThenLeave()

    def displayScreenThenLeave(self):
        # 'time.sleep(3)' is a stand-in for "execute some code here"
        time.sleep(3)
        self.changeScreen()

    # I want this function to send the user back to ScreenOne.
    def changeScreen(self):
        pass

class …
Run Code Online (Sandbox Code Playgroud)

python python-2.7 kivy

2
推荐指数
2
解决办法
1万
查看次数

标签 统计

go ×1

gofmt ×1

kivy ×1

python ×1

python-2.7 ×1