Clearing the screen and Julia's exploratory tools (equivalent of Python's dir function)

1,090 views
Skip to first unread message

Nafiul Islam

unread,
May 2, 2014, 6:09:56 PM5/2/14
to julia...@googlegroups.com
Hi (again)!

Hopefully a (slightly) more intelligent question this time. I've been successfully able to run shell commands from Julia through Base.run, and the first thing I did was clear the screen:

julia> Base.run(`clear`)

However, I wanted to ask, if there was an inbuilt function that does this. Making one yourself is trivial of course:

julia> f() = Base.run(`clear`)
f (generic function with 1 method)

But creating one for each session is rather annoying.

Second question is that I'm looking for something like Python's dir function:

In [3]: import os

In [4]: dir(os)
Out[4]:
['EX_CANTCREAT',
 'EX_CONFIG',
 'EX_DATAERR',
 'EX_IOERR',
 ....
 ....
 ....
 'wait',
 'wait3',
 'wait4',
 'waitpid',
 'walk',
 'write']

In essence, it gives you a list of all the objects/functions that are available to that package. Now, I've taken a look at the help function in Julia, and its helpful on a function, it can give you information about a function that you know exist:

julia> help(run)
Base.run(command)

   Run a command object, constructed with backticks. Throws an error
   if anything goes wrong, including the process exiting with a non-
   zero status.

However, it is Base that has this function. Is there a tool like dir that I can leverage to explore Julia?

Kevin Squire

unread,
May 2, 2014, 7:46:27 PM5/2/14
to julia...@googlegroups.com
There's no command, but "ctrl-l" (ctrl-ell) clears the screen.

Cheers, Kevin

Ivar Nesje

unread,
May 3, 2014, 1:03:49 AM5/3/14
to julia...@googlegroups.com
I think the equivalent to Python's dir() command would be `names()`.

If you want to customize julia on startup, you can create a .juliarc.jl file and that file will be included at startup.

There is also the shell> mode in the REPL that allows you to type shell commands directly. To get into on the shell> mode, you can start a line with a ;

Ivar Nesje

unread,
May 3, 2014, 1:06:32 AM5/3/14
to julia...@googlegroups.com
The shell mode is a shortcut for Base.run(`clear`) where you just type ;clear

Leah Hanson

unread,
May 3, 2014, 10:32:40 AM5/3/14
to julia...@googlegroups.com
If you're looking for more exploratory-type functions/tools, I have a list of them here: http://blog.leahhanson.us/julia-helps.html

My blog post is missing the `whos` function, which is a more human-readable way to see everything a Package/Module exports:
~~~
julia> using DataFrames

julia> whos(DataFrames)
@~                            Function
AbstractDataFrame             DataType
DataFrame                     DataType
DataFrameRow                  DataType
DataFrames                    Module
EachCol                       Function
EachRow                       Function
Formula                       DataType
GroupApplied                  DataType
GroupedDataFrame              DataType
ModelFrame                    DataType
.... (lots more stuff)
~~~

-- Leah

Nafiul Islam

unread,
May 4, 2014, 2:33:31 AM5/4/14
to julia...@googlegroups.com
Thank you all so very much for the help. Now, I can learn more Julia without bothering everyone all the time :)
Reply all
Reply to author
Forward
0 new messages