golang import all 类似python import * 效果
2024-08-31 04:01:49
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:\n", 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
最新文章
- 电脑莫名其妙的被装上了流氓软件DNSunlocker的解决办法
- poj1741 (点分治)
- PTA Hashing
- juery与表单中name=";nodeName";引起的冲突
- iOS支持图文混排的按钮(UIButton)
- select实现选中跳转
- STM32F4系统时钟配置及描述
- Servlet3.1规范和JSP2.3规范
- 201521123047 《Java程序设计》第4周学习总结
- Writing Science 笔记 6.20
- Python中的正则表达式(re)
- Hessian学习(springboot环境)
- C. Ehab and a 2-operation task
- 黄聪:HBuilder复制PHP项目后,【转到定位】功能失效
- 【Spring】SpringMVC之上传文件
- WebRTC 源码分析(四):VideoCRE 与内存抖动优化
- jsp页面的el表达式取数据
- React Native教程
- ubuntu自带截图工具gnome-screenshot
- C++解析(26):函数模板与类模板