D R
D R

Reputation: 22492

Name clashes in Go imports

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?

Upvotes: 3

Views: 526

Answers (1)

peterSO
peterSO

Reputation: 166598

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

Upvotes: 5

Related Questions