In Python 3.6+ the following works:
import sys
print(f"Program name is {sys.argv[0]}")
Program name is C:\Program Files\JetBrains\PyCharm Community Edition 2018.1\helpers\pydev\pydevconsole.py
How do I do this in Julia?
In a Julia program file, this works:
println("Program name is ", PROGRAM_FILE)
""" Output
Program name is StackQuestion.jl
"""
In the Julia 1.0 REPL there is no output:
julia> print("The program name is ", PROGRAM_FILE)
The program name is
This should not be a problem since getting the program name is something one would typically want to do within their running program.
A useful tip from the Julia 1.0 docs relating to the program file name is: https://docs.julialang.org/en/v1/manual/faq/#
"How do I check if the current file is being run as the main script?
When a file is run as the main script using julia file.jl one might want to activate extra functionality like command line argument handling. A way to determine that a file is run in this fashion is to check if abspath(PROGRAM_FILE) == @__FILE__ is true."
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With