Search code examples
packagejuliausing

Julia - How to Import Part of Package and call Using this package?


I wanted to use ProgressMeter (for progress bars) and DataStructures (for orderedDicts) in Julia v1.1:

using ProgressMeter
using DataStrctures

However, both of these packages export an update! method. So I had a warning telling me to specify from which package it comes from and tried to fix it by :

ProgressMeter.update!(...)

I didn't want it to specify it at each update! in my code, so I decided that I want to only use DataStructures.OrderedDict.

However, when I do this with import :

import DataStructures.OrderedDict

I can't call using DataStructures after this to avoid DataStructures.{OrderedDict, or something linked to orderedDict} each time I use OrderedDict as using imports everything on DataStructures and re-enter in conflicts with the update! from ProgressMeter.

What should I do?


Solution

  • You can explicitly bring update! from ProgressMeter into scope.

    using DataStructures
    using ProgressMeter
    using ProgressMeter: update!
    

    Now there should be no warning and update! alone should refer to the methods in ProgressMeter. If you need to call the update! in DataStructures, you should qualify it with the name DataStructures.