Recent Changes - Search:

Oktatás

* Programozás 2
  + feladatsor
  + C feladatsor
  + Python feladatsor
  + GitHub oldal

* Szkriptnyelvek
  + feladatsor
  + quick link

* Adator. prog.
  + feladatsor
  + quick link

Teaching

• Prog. for Data Sci.
  ▸ exercises
  ▸ quick link

teaching assets


Félévek

* 2026/27/1
* archívum


Linkek

* kalendárium
* tételsorok
* jegyzetek
* szakdolgozat / PhD
* ösztöndíjak
* certificates
* C lang.
* C#
* D lang.
* Java
* Nim
* Nim2
  + exercises
* XC=BASIC
* old
  ✦C++, ✦Clojure, ✦Scala


[ edit | logout ]
[ sandbox | passwd ]

How to import a package

Importing is very similar to Python.

Import just some parts of a package

The following code drops an error:

# read a line of words from stdin and print the first word reversed
import std/strutils
import std/unicode     # reversed

let parts = stdin.readLine.splitWhitespace
echo parts[0].reversed

Error message:

main.nim(9, 27) Error: ambiguous call; both strutils.splitWhitespace(s: string, maxsplit: int) 
[func declared in /home/jabba/.choosenim/toolchains/nim-2.4.0/lib/pure/strutils.nim(924, 6)] and 
unicode.splitWhitespace(s: string) [proc declared in 
/home/jabba/.choosenim/toolchains/nim-2.4.0/lib/pure/unicode.nim(1464, 6)] match for: (string)

The error comes from std/unicode and std/strutils both exporting a splitWhitespace for string, so the compiler can’t pick one.

Solution #1

From the package unicode I only need the function reversed. So it'd be enough to import only that function:

import std/strutils
from std/unicode import reversed

let parts = stdin.readLine.splitWhitespace
echo parts[0].reversed

Solution #2

To avoid ambiguity, we can qualify the call explicitly:

import std/strutils
import std/unicode

let parts = strutils.splitWhitespace(stdin.readLine)
echo parts[0].reversed

Here it's clear which splitWhitespace() we want to call.

Cloud City

  

Blogjaim, hobbi projektjeim

* The Ubuntu Incident
* Python Adventures
* @GitHub
* heroku
* extra
* haladó Python
* YouTube listák


Debrecen | la France


[ edit ]

Edit - History - Print *** Report - Recent Changes - Search
Page last modified on 2026 November 05, 16:42