How to get the global variables?


#1

Hi,
I was looking for a function, which gives the global variables available within the scope?

Is there such a function.

Thanks.


#2
help?> whos                                                                                                                                                              
search: whos print_with_color                                                                                                                                            

  whos(io::IO=STDOUT, m::Module=current_module(), pattern::Regex=r"")                                                                                                    
                                                                                                                                                                         
  Print information about exported global variables in a module, optionally restricted to those matching pattern.                                                        

  The memory consumption estimate is an approximate lower bound on the size of the internal structure of the object.

#3

Thanks you are awesome.!


#4

I have one question though.

module DFT
           global a
           export f
           f()=44
       end

whos(DFT)
                           DFT   1540 bytes  Module
                             f      0 bytes  DFT.#f

why is :a not present in the output?


#5

Each module defines its own, separate scope: https://docs.julialang.org/en/stable/manual/variables-and-scoping/#Global-Scope-1. Edit: I misread. I guess whos chooses to only display exported variables, as stated in its doc: “Print information about exported global variables in a module”.