# Howto resolve a module or a field by its full name

**URL:** <https://discourse.julialang.org/t/howto-resolve-a-module-or-a-field-by-its-full-name/88550>\
**Category:** General Usage\
**Tags:** module, reflection\
**Created:** [October 11, 2022, 4:24am UTC](https://discourse.julialang.org/t/howto-resolve-a-module-or-a-field-by-its-full-name/88550 "2022-10-11T04:24:24Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![o314](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/o314/32/252_2.png) [@o314](https://discourse.julialang.org/u/o314)\
**Post date:** [October 11, 2022, 4:24am UTC](https://discourse.julialang.org/t/howto-resolve-a-module-or-a-field-by-its-full-name/88550/1 "2022-10-11T04:24:24Z")

</div>

Hi,

I am looking for a way to resolve a module or a field by its full name  
I have not found anything in Base (reflection.jl etc.)  
Is there anything recommended ? more than my own version there :

```julia
field(qname::Tuple{Symbol,Vararg{Symbol}}; root::Module=Main, do_walk_datatype::Bool=false) =
    let r = foldl(qname; init=(true,root)) do acc,n
                acc[1] || return acc
                do_walk_datatype || acc[2] isa Module || return (false,)
                e = try getfield(acc[2], n); catch ex; nothing end
                e !== nothing || return (false,)
                (true, e)
            end ;
        r[1] || throw(ArgumentError(join(qname,'.')))
        r[2]
    end
field(name::Symbol; root::Module=Main) = field((name,); root)

```

```julia
using Test
@testset begin
    @test field((:Base, :Iterators)) == Base.Iterators
    @test field((:Base, :Iterators, :takewhile)) == Base.Iterators.takewhile
    @test field((:Iterators, :takewhile); root=Base) == Base.Iterators.takewhile
    @test_throws ArgumentError field((:Base, :Iterators, :takewhile2))
    @test_throws ArgumentError field((:Base,:stdout,:buffer,:data))
    @test field((:Base,:stdout,:buffer,:data); do_walk_datatype=true) isa AbstractVector{UInt8}
    @test field(:sin) == field((:Base,:sin))
end

```

Thanks

–  
PS `hasfield(::Type,::Symbol)` exists but not `hasfield(::Module,::Symbol)`

SEE

- [Resolving a module by its name](https://discourse.julialang.org/t/resolving-a-module-by-its-name/30569)
