Go导入中的名称冲突

huangapple go评论63阅读模式
英文:

Name clashes in Go imports

问题

考虑下面的Go代码..

package main

import "go/token"
import "python/token"

func main() {
     x := token.INDENT
}

如何解决上述代码中token的歧义问题?是否有类似于Python表达式import python.token as pytoken的方式?

英文:

Consider the Go code below..

package main

import "go/token"
import "python/token"

func main() {
     x := token.INDENT
}

What is the best way to solve the ambiguity of token in the above code? Is there something similar to the python expression of import python.token as pytoken?

答案1

得分: 5

例如,

package main

import "go/token"
import pytoken "python/token"

func main() {
     g := token.INDENT    // "go/token"
     p := pytoken.INDENT  // "python/token"
}

导入声明

英文:

For example,

package main

import "go/token"
import pytoken "python/token"

func main() {
     g := token.INDENT    // "go/token"
     p := pytoken.INDENT  // "python/token"
}

Import declarations

huangapple
  • 本文由 发表于 2011年12月7日 17:10:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/8412766.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定