go - Golang,安装后导入 pkg
问题描述
我很新,我来自python。为了学习,我正在重新创建 python 内置函数。
我被困在我的第一个功能上——范围,它还不是生成器。
我希望能够:
// testmain.go
package main
import (
"pyfuncs"
"fmt"
)
func main(){
fmt.Println( pyfuncs.range(12) )
fmt.Println( pyfuncs.range(-12, -2, 3) )
}
输出:
[1 2 3 4 5 6 7 8 9 10 11 12]
[-12 -9 -6 -3]
*/
我$GOPATH/
的结构是这样的:
/$GOPATH/
|
| src/
| | imports/
| | | pyfuncs/
| | | | pyrange.go (package pyfuncs)
| | learn/
| | | testmain.go (package main) <- This doesnt work
| | | ArraysAndSlices/...
| | | Printf/...
|
| pkg/
| | linux_amd64/
| | | imports/
| | | | pyfuncs.a
| bin/...
我在 testmain.go 如何从 pyfuncs 目录访问函数?
我希望能够从 fmt 等未来的每个项目中访问它们。在 python 中,我只是将它们推到lib/
python 文件夹中的目录中。
这些是错误:
cannot refer to unexported name pyfuncs.pyRange
undefined: pyfuncs.pyRange
解决方案
要导入的函数必须以大写字母开头。
一步步:
cd imports/pyfuncs
go install
- 当尝试访问 pyfuncs 时
imoprt "imports/pyfuncs"
- 通过以下方式访问该功能
pyfuncs.PyRange
推荐阅读
- numpy - 在布尔表达式中手动广播 numpy?
- json - 使用模板或工具编辑 (conf) json 文件
- vue.js - Vuejs 从扩展组件事件中更新父组件数据
- azure - 如何在 Azure 数据工厂中添加动态连接字符串
- java - 我的数组列表数据未显示在列表视图中仅包名称显示在列表视图中
- java - 在 try-with-resources 中打开连接 - 第二个资源取决于第一个
- javascript - Javascript 上的 mssql 语句
- google-apps-script - 环聊机器人如何在卡片消息中@提及用户
- jquery - Vue v-for 在幻灯片中没有正确渲染阴影
- android-studio - Android Studio 致命错误:打开旧文件时出现 JUnit 和 Studio.Core 异常