• golang import all 类似python import * 效果


    import "io/ioutil"
    
    func main() { 
        content, err = iotuil.ReadFile("somefile.txt")
        // etc..
    }

    =》

    I guess this doesn't really answer your question, but if you want, you can actually call the methods without explicitly stating the package - just import with a . in front of the names (but this is not recommended; see below):

    package main
    
    import (
      . "fmt"
      . "io/ioutil"
    )
    
    func main () {
      content, err := ReadFile("testfile")
      if err != nil {
        Println("Errors")
      }
      Println("My file:
    ", string(content))
    }

    Note @jimt's comment below - this practice is not advised outside of tests as it could cause name conflicts with future releases. Also, definitely agree with @DavidGrayson's point of being nicer to read/see where things come from.

    参考:https://stackoverflow.com/questions/12925450/importing-packages-in-go

  • 相关阅读:
    第1次实践作业
    Beta版本演示
    2019 SDN上机第7次作业
    Beta冲刺(4/4)
    Beta冲刺(3/4)
    Beta冲刺(2/4)
    Beta冲刺(1/4)
    2019 SDN上机第6次作业
    2019 SDN上机第5次作业
    SDN课程阅读作业(2)
  • 原文地址:https://www.cnblogs.com/bonelee/p/6899687.html
Copyright © 2020-2023  润新知