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:\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















本文转自张昺华-sky博客园博客,原文链接:http://www.cnblogs.com/bonelee/p/6899687.html,如需转载请自行联系原作者


相关文章
|
1月前
|
数据可视化 数据挖掘 开发者
import有什么用,python中怎么使用import
import有什么用,python中怎么使用import
26 1
|
4月前
|
API Python
python 详细理解 import ---- openstack自动import class 到 特定命名空间
python 详细理解 import ---- openstack自动import class 到 特定命名空间
46 0
|
1月前
|
Python
[Python] 如何用import导入模块
[Python] 如何用import导入模块
23 0
|
3月前
|
C++ Python
python工程中import要点提炼
python工程中import要点提炼
|
3月前
|
Python
Python小姿势 - import random
Python小姿势 - import random
|
3月前
|
Python
Python小姿势 - import requests
Python小姿势 - import requests
|
4月前
|
开发者 Python
【python】tkinter组件,from Tkinter import * 与 import Tkinter 的区别
【python】tkinter组件,from Tkinter import * 与 import Tkinter 的区别
53 0
|
4月前
|
编译器 Python
Python 完美解决 Import "模块" could not be resolved ...
Python 完美解决 Import "模块" could not be resolved ...
48 0
|
4月前
|
XML 数据格式 Python
Python解释import、from ... import ... 和 from ... import *的区别。
解释import、from ... import ... 和 from ... import *的区别。
|
5月前
|
Linux 开发工具 C++
【vcpkg】像Python一样方便的import 自己的c++库
使用此种方式可无需设置 CMAKE_TOOLCHAIN_FILE 即可使用 vcpkg,且更容易完成配置工作。
197 0