Import inside a method, close to where it is used.

Local Import

LocalImport.scala
object Main {
  def main(args: Array[String]): Unit = {
    val n = 
    import scala.math.sqrt
    val root = sqrt(n).toInt

    println("n=" + n)
    println("root=" + root)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val n = 
    import scala.math.sqrt
    val root = sqrt(n).toInt

    println("n=" + n)
    println("root=" + root)
  }
}
object Main {
  def main(args: Array[String]): Unit = {
    val n = 
    import scala.math.sqrt
    val root = sqrt(n).toInt

    println("n=" + n)
    println("root=" + root)
  }
}
local-import An import can sit inside a method so the name is only visible there. This keeps a helper like `sqrt` scoped to the code that needs it.